Database engine

ABSTRACT

A processor functioning as a coprocessor attached to a central processing complex provides efficient execution of the functions required for database processing: sorting, merging, joining, searching and manipulating fields in a host memory system. The specialized functional units: a memory interface and field extractor/assembler, a Predicate Evaluator, a combined sort/merge/join unit, a hasher, and a microcoded control processor, are all centered around a partitioned Working Store. Each functional unit is pipelined and optimized according to the function it performs, and executes its portion of the query efficiently. All functional units execute simultaneously under the control processor to achieve the desired results. Many different database functions can be performed by chaining simple operations together. The processor can effectively replace the CPU bound portions of complex database operations with functions that run at the maximum memory access rate improving performance on complex queries.

This is a divisional of application Ser. No. 07/499,844 filed on Mar.27, 1990, now U.S. Pat. No. 5,210,870.

BACKGROUND OF THE INVENTION

1. Field of the Invention

This invention relates to database processing.

2. Related Art

Database processing is a widely known and commercially significantaspect of the data processing field. A database is a collection of dataorganized into records. Computer operations which are performed onand/or using these data records are referred to as database processing.A database manager is the package of database processing operations usedto access and manipulate the database.

Database processing commonly involves operations such as sorting,merging, searching and joining. Set operations such as union,intersection and difference are also common aspects of databaseprocessing. Conventionally, these operations have been performed bysoftware algorithms requiring significant amounts of processor executiontime. In large databases, the processor execution time can beprohibitive, significantly degrading the performance of softwaredatabase managers.

One aspect of database processing involves searching for records thatmeet a certain criteria. For example, a search might scan all records inthe database and return every record that has column "X" equal to somevalue. In a more complex case, the search might scan and retrieverecords based on a predicate equation involving many columns and values.Since the databases can be very large, (e.g. hundreds of millions ofrecords), the searching algorithms used in conventional softwaredatabase management systems can take hours to process.

Another aspect of database processing involves the extraction of sortkeys and search fields from the database records. In sorting andsearching applications, the sort key or field on which a search isdefined are often spread throughout the records and must be extractedinto a useable format before the operation can proceed. For sorting thismeans getting each key field and concatenating them in precedence orderso that they can be treated as one large key. For searching, the columnsof a table that are being searched or selected must be extracted fromthe rows. Conventionally, these and many other database operations canuse significant amounts of CPU time.

There have been a number of attempts to provide solutions which"off-load" the CPU of some of the database processing tasks. One suchsolution was to provide a computer system with a specialized sortprocessor to handle sorting tasks which would otherwise be executed bythe CPU. FIG. 1 is an illustration of a such a prior art sort processor.

The sort processor 100 of FIG. 1 shares a main memory bus 102 with acentral processing unit 104. A main memory 106 communicates with thecentral processing unit 104 through a first set of communications lines108 and with the sort processor 100 through a second set ofcommunications lines 110. The central processing unit 104 and the sortprocessor 100 are interconnected by a start control line 112 and andinterrupt line 114.

During database processing, random records stored in a peripheral file116 are transferred to the main memory 106. A control program theninitiates the action of the sort processor 100. Under firmware control,the key words are transferred from the main memory 106 to the sortprocessor 100 and then sorted. The autonomous action of the sortprocessor 100 results in savings of Central Processing Unit time andsimplification and reduction of programming efforts.

While the sort processor 100 of FIG. 1 provided an advance overcontemporaneous software database processors, the solution was onlypartial. Sorting is but one aspect of database processing. Otheroperations such as searching, joining of tables and set operations alsotake up significant amounts of CPU time. Further, although the sortprocessor of FIG. 1 operated relatively autonomously from the remainderof the system, its internal sorting algorithm was implemented inmicrocode. Thus the sort processor of FIG. 1 was limited by many of thesame constraints as sort programs which would otherwise be executed bythe CPU.

The sort processor 100 of FIG. 1 is also subject to performancelimitations in that it shares the main memory 106 with the centralprocessor 104 on a low priority basis and along a single memory bus 102.The competition for main memory access time along the single bus path(albeit reduced relative to systems having no sort processor) can causea bottleneck for data traffic between the main memory 106 and the sortprocessor 100.

Another approach to database processing off-loads some of the databaseprocessing tasks traditionally handled by the CPU to a vector processingelement. FIG. 2 is an illustration of one such prior art relational database managing system utilizing a vector processor. A central processor200 includes a scalar processor 202 and a vector processor 204. Both thevector and scalar processors have access to a main memory 206 and asubsidiary storage 208.

In operation, a database command issued from an application program 210is examined by a relational database managing program 212. The databasemanaging program 212 identifies the command, analyzes it, and thengenerates codes which which designate a determined process sequence.During database processing, required data is loaded into a data bufferarea 214 in the main memory 206 from a page area in in the subsidiarystorage 208. Under control of the process sequence codes, the data inthe buffer area 214 is rearranged in the form of a vector structure. Theresultant vector data elements are stored in a vector area 216.

When the process sequence codes indicate the processing of the vectordata, a sequence of vector instructions are executed by the vectorprocessor 204. Under control of the vector instructions, the vectorprocessor 204 processes the data in the vector area 216 in accordancewith the designated processes sequence.

One constraint of the database managing system of FIG. 2 is that as aconsequence of its reliance on vector processing, the database must begenerated in or converted to a vector format prior to being processed.This conversion process can, in itself, take a significant amount oftime and can slow the data base processing operation.

A second constraint of the database managing system of FIG. 2 is thatthe associated vector processing hardware is programmed at theinstruction level (i.e. it is left to the programmer to write theinstruction primitives required to perform the database processingfunctions). These instructions are executed by the vector processinghardware synchronously within the database management program. Thus, thedatabase manager program is dedicated to a single task while theinstructions are being executed. Further, as each primitive instructionis executed it requires CPU time. The CPU is, therefore, not completelyfree of database processing duties until the entire series of primitivesis executed.

Yet a third constraint of the database managing system of FIG. 2 is thatthe vector processing approach adds levels of indirection to thedatabase processing operation. In vector formatted databases, a seriesof pointers are used to locate the actual data of interest. A locationin one table will often point to another location in another table andso on. This indirection can increase processing time of databaseoperations.

SUMMARY OF THE INVENTION

It is an object of the invention to exploit functional level parallelismto enhance the overall processing speed of database operations beyondthat achieved by prior art database processors.

It is a further object of the invention to process database operationsat or near system memory bandwidth speeds.

It is a further object of this invention to process, in an attachedcoprocessor environment, a command list generated by a conventionalsoftware database processing program.

In accordance with these objectives, the inventors have provided aDatabase Engine (DBE), which provides fast processing for basic databasefunctions. In the preferred embodiment, the Database Engine includes anextractor/memory interface unit which provides access to a system memoryand extracts the data to be processed therefrom, a local working memorywhich temporarily stores the data to be processed, a plurality ofautonomous processing elements which each perform a specialized databaseprocessing function, and a control processor which parses databasecommands from a database manager into subfunctions and distributes thesubfunctions among the processing elements.

By providing hardware to assist and accelerate the processing of basicdatabase functions, the Database Engine can significantly reduce theexecution time of many database operations.

Advantageously, the Database Engine overcomes many of the constraints ofprior art database coprocessors. In contrast to the system of FIG. 2,the Database Engine does not require vector formatted records. Thus, thedatabase engine eliminates much of the processing overhead present inthe FIG. 2 system. Further, unlike the vector processor of FIG. 2, theDatabase Engine can be controlled with macro commands rather thanrequiring central processor instruction level programming.

Unlike the system of FIG. 1, the Database Engine does not need tocompete with the CPU for main memory access time by way of a common databus. In one embodiment, the database engine is coupled to the systemspage storage. The page storage acts as a directly addressable mainmemory for the database engine but appears only as a paging memory tothe systems central processors. This enables large databases to be fixedin the paging memory and minimizes competition with the centralprocessors for main memory accesses.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 is diagram of a prior art sort processor system.

FIG. 2 is a diagram of a prior art database managing system.

FIG. 3 is a block diagram overview of the Database Engine according to apreferred embodiment of the present invention.

FIG. 4 is a block diagram illustration of the logical connection of theDatabase Engine of FIG. 3 into a computer system having a paging memoryand a main memory.

FIGS. 5A and 5B are, respectively, top and bottom halves of a diagramillustrating an embodiment of the Control Processor of FIG. 3.

FIGS. 6A and 6B are, respectively, top and bottom halves of a diagramillustrating an embodiment of the Predicate Evaluator (DBPE) of FIG. 1.

FIG. 7 is a diagram illustrating an embodiment of the Sort/Merge Unit ofFIG. 3. The interaction between the Sort/Merge Unit and the WorkingStore of FIG. 3 is also illustrated.

FIG. 8 is an example of a block sort.

FIG. 9 is an illustration of the state of the Working Store and pointerarrays during a block sort using the sort/merge unit of FIG. 7.

FIGS. 10A and 10B are, respectively, top and bottom halves of a flowchart of the binary sort/merge algorithm used by the Sort/Merge Unit(DBSM) of FIG. 3.

FIG. 11 is an illustration of the hardware additions to the Sort/MergeUnit of FIG. 7 which implement Tournament Tree Codeword Techniques.

FIG. 12 is an illustration of a conventional tournament tree.

FIGS. 13A-13C illustrate progressive states of a tournament treeimplemented in the Working Store and pointer arrays of FIG. 7.

FIGS. 14A, 14B are flow charts of a sort algorithm using codewordtechniques implemented using the additional hardware of FIG. 11.

FIG. 15 is a more detailed diagram illustrating the structure of theHash-code Generator (DBHG) of FIG. 3.

FIG. 16 is a block diagram of the Extractor/Memory Interface Unit (DBEM)of FIG. 3.

FIGS. 17A, 17B are, respectively, top and bottom halves of a moredetailed diagram illustrating the structure of the Extractor/MemoryInterface Unit (DBEM) of FIGS. 3 and 16.

FIGS. 18A, 18B and 18C are a flowchart of the operation of the DBEM ofFIGS. 17A, 17B.

FIG. 19 is a block diagram of a DBSM modified to perform a front-backmerge.

FIG. 20 is a block diagram of a 16-way merge tree with a 4-waycomparator.

FIG. 21 is a diagram of a 4-way merge sort comparator which produces anordered list of pointers to four input keys.

FIG. 22 is a diagram of a four pipe, 4-way comparator sort engine.

Like elements which appear in more than one figure have been assignedlike reference numerals.

IV. DESCRIPTION OF THE PREFERRED EMBODIMENTS a. Database Engine

The Database Engine (DBE) is a special purpose processor designed toquickly evaluate relational databases and provide fast sorting of data.The Database Engine performs the core functions required for databaseprocessing including sorting, merging, joining, searching, andmanipulating fields. The Database Engine provides performanceimprovements over many of the best known software approaches to the sameproblems by taking advantage of the overlap between processing andmemory access time that can be obtained in a specialized hardwareimplementation.

The overall structure of the Database Engine is illustrated in FIG. 3.The Database Engine 300 comprises five hardware processing elements(designated by reference numerals 302-310) and a Working Store 312. Twointernal multibit data busses 316,318 provide data flow between theWorking Store 312 and the processing elements 302-310. An internalmultibit control bus 320 provides a control data path between theprocessing elements. Externally, a system memory bus 322 is providedbetween an extractor/memory interface unit 308 and the system memory(not shown in FIG. 3).

The processing elements 302-310 and the Working Store 312 work inconcert to process database queries. The Sort/Merge unit 302 performssorts, merges, joins, and set operations. Searching is performed by thePredicate Evaluator 304. A hardware Hash-Code Generator 306 is providedto improve the performance of EQUIJOINs on two databases. Record fieldextraction and memory access functions are performed by theExtractor/Memory Interface Unit 308. Operations performed by theforegoing processing elements are initiated under the control of theControl Processor 310.

The Database Engine 300 works in conjunction with database applicationsoftware running on a host system. An example of such software is DB2(an IBM database application program that runs under MVS.) Theapplication software does all of the I/O required to read the databaseinto system memory. The application software also creates the DatabaseEngine commands, the database object descriptors, and the predicate;then puts them into the system memory where they can be accessed by theDatabase Engine 300.

FIG. 4 illustrates the system attachment of the Database Engine 300 in aexemplary system environment. In the system of FIG. 4, the DatabaseEngine 300 is shown configured in a multiprocessor system having threecentral processors (CPs) 402-406, I/O channels 408, and a system memorycomprising a main storage 410 and a page storage 412. The page storageacts as a paging memory to the central processors 402-406. Pages of dataare transferred from the page storage to the main storage, under controlof the central processors 402-406, by way of a memory data bus 414. Thecentral processors then access the data in main storage by way of aswitch or system controller 416. An example of such a system isdescribed in U.S. Pat. Nos. 4,476,524 to Brown and 4,394,731 to Fluscheet al., which are both incorporated by reference in their entireties, asif printed in full below.

The switch 416 is of the self routing, non-blocking crossbar type.Specifically, the switch 416 provides simultaneous multibit data pathsbetween the main storage 410 and any one of the system elements (300,402-408), and between the page storage 412 and any other one of thesystem elements. For example, the switch 416 can provide a first datapath between the page storage 412 and the Database Engine 300 while atthe same time providing a second data path between one of the centralprocessors 402-406 and the main storage 410.

Alternatively, the system memory (main and page storages 410, 412) canbe multi-ported and data transfer between the Database Engine 300 andthe system memory (410, 412) can be provided by directly connected highbandwidth buses 420, 422. Further, the central processors can beprovided with access the main storage through a port or ports by way ofa CP data busses such as the one shown by reference numeral 424. Asimilar connection could be provided for the between the system memoryand the I/O channels 408. In such an embodiment the switch 416 can beeliminated.

The configuration of FIG. 4 enables the Database Engine 300 to accesssystem memory (410, 412) directly, without having to go through thecentral processor to generate requests. Thus, the Database Engine canaccess the page storage 412 as a main memory. As described above, in thesystem of FIG. 4 the page storage acts 412 as a paging memory to the CPs402-406. This attachment system/method enables the Database Engine torun as a logically asynchronous processor in the system with minimaleffect on the CPs.

Having direct access to both the main and page storages 410, 412provides a number of ways for the database engine to access commands anddata records. For example, the database can be accessed from the mainstorage and portions can be paged in as needed. Alternatively, thedatabase can be fixed in the page storage 412 and accessed directly,thus avoiding the I/O costs entailed with saving and restoring thedatabase to a direct access storage device (DASD). In any event,performance requirements, memory size, and the type of memory availablein a particular system are factors which should be taken into account indetermining where the database should reside in the system memory.

With respect to the system environment of FIG. 4, data that is needed bythe Database Engine 300 is fixed in the system memory (either the mainstorage 410 or the page storage 412) by the operating system prior toissuing the start signal. A list of page or record addresses is thengiven to the Database Engine to tell it where in the system memory (410,412) the data resides and in what order to access each fixed block.

A Database Engine operation is initiated via a command sequence that isconstructed by the database application program. The command sequence isplaced in the system memory through the operating system prior toinvoking the operation of the Database Engine. Once the Database Engine300 has been started, it runs asynchronously, accessing the commands,descriptors, and data (out of system memory) as it needs to without anyinterruption of the central processors 402-406. When the operation iscomplete, an interrupt is issued back to the calling program.

The operation of the Database Engine 300 will now be explained in moredetail by example of the processing of a search with sort command.Reference will be made to FIGS. 3 and 4. Through the receipt of a startsignal, the Control Processor 310 is signaled that a database command,encountered by the host CPU, exists in the system memory. The startsignalling is done through the memory interface portion of theExtractor/Memory Interface Unit 308 and includes the address of adatabase command block (described in detail elsewhere) in the systemmemory. On receiving the Start DBE signal, the Control Processor 310fetches the database command block from the system memory and stores itinternally.

Next, the Control Processor 310 parses the database command informationinto setup and processing information for each of the other processingelements 304-308. The database descriptor and field information is usedto initialize the extractor/assembler function of the Extractor/MemoryInterface Unit 308, the selection predicate is loaded into instructionand constant tables within Predicate Evaluator 304, and the sort key isused to set up the Sort/Merge unit 302. Once each processing element isloaded with its required information (function and initialization data),the execution phase begins.

The database command is executed by processing blocks of data througheach processing element in a pipelined fashion until the entire databasehas been processed. In the case of a search with a sort, the data isfirst processed by the extractor portion of the Extractor/MemoryInterface Unit 308 to put the needed data into the Working store 312.Next, the Predicate Evaluator 304 processes the records in Working Store312 to select ones which meet the selection predicate. The Sort/Mergeunit 302 then sorts the selected records into order based on the key.

The sorting and predicate evaluation operations are performed in blocksof the size of the Working Store 312 and are repeated until the entiredatabase has been processed. The sort portion of the command, forexample, may take several merge passes to be able to merge a largedatabase. In such a case, an assembler function of the Extractor/MemoryInterface Unit 308 is used to write intermediate results to a temporarymemory area in the system memory. On the final merge pass, the outputrecords are assembled into their correct format and written to an outputmemory area (designated by the command), by the assembler function ofthe Extractor/Memory Interface Unit 308.

Once the last record is assembled and placed into the system memory, theControl Processor 310 collects any operational or error status andplaces it in a status area in the system memory. The Control Processor310 then signals the initiating host CPU that the operation is complete.The Database Engine 300 is then ready to process another command.

Advantageously, the Database Engine's System memory accesses can beoverlapped with database processing time. Database records can beassembled by the Database Engine 300 and returned to system memory whilestill other records are in the midst of being processed. Further, oncestarted by the Control Processor 310, each of the other processingelements 304-308 can operate in parallel, as long as the function can bepartitioned to allow simultaneous access to the Working Storepartitions. Thus the Database Engine can execute database queries atvery close to the system memory access rate.

Although the above example describes a search with sort execution, itshould be understood that the Database Engine can perform many differentoperations, including search, sort, merge, join, etc., which all executein the same data-block pipelined fashion.

The Database Engine command set includes the core relational databasefunctions that are used to process database queries. These functions arethe basic components of the queries, and can be chained together toproduce a complex database query. The core functions implemented by theDatabase Engine are:

1. Sorting. A database is sorted based on a given column or combinationof columns and returned in sorted order. The sort key can be any length(up to 32K bytes long in the preferred embodiment).

2. Searching. The database is evaluated and the results are restrictedto rows that match a given predicate, e.g., find all records wherecolumn 1='xyz' is a search operation. A subset of the full database isreturned in which all records have column 1 equal to 'xyz'. The "column1='xyz'" is called the predicate and can be simple (as in this case) orcomplex. The Database Engine allows the following comparison operatorsto be used: "equal", "greater than or equal", "less than or equal", "notequal", "less than" and "greater than". Complex predicates are composedof simple predicates connected with AND, OR, and NOT and other Booleanoperators.

3. Selection. A subset of the columns in the database can be chosen fromthe database and returned by the selection operation. The selectionoperation returns a vertical subset of the database columns.

4. Set Operations. The set operators include union, intersection,difference, and cross product. These are performed as defined forgeneral set theory.

5. Join Operations. Join operations are performed according to the typeof join. The join operator can be "equal", "greater than or equal","less than or equal", "not equal", "less than" and "greater than" orcombinations of the above connected by the Boolean operators AND, OR,and NOT. Note that outer joins can be performed as well, although theycreate large resultant databases.

b. Command Format

The command block is a data structure that provides both command andaddress information to the Database Engine. The command block isconstructed by the database application software and passed to theDatabase Engine 300, during initialization, by Way of the system memory.The Database Engine 300 is informed that the command block is present inthe system memory through receipt of the Start DBE command. The commandblock contains the following information.

1. The type of command that is to be executed: sort, merge, join,selection, search, union, intersection, difference, cross product, ordivision.

2. The address of the database descriptor(s) in memory. There can be upto three database descriptors used, two inputs and an output. The outputarea is also used as the temporary work area during processing.

3. The address of the predicate to be used during command processing.

4. The fields from the databases that are to be used for the command andthe output fields to be given.

5. If an index is available, it can also be specified in the commandblock.

The database descriptor is used by various commands to identify aparticular database. For example, the MERGE command can have any numberof databases (up to 128 in the preferred embodiment) as inputs and onedatabase as an outpot. Each of the remaining commands preferablyprocesses one or two databases as inputs and have a third as an output.Each of these databases are identified to the Database Engine by adatabase descriptor. Each descriptor contains the following information:

A. Starting address of the database.

B. The format of the database, either DB2 or compact.

The Database Engine can process the DB2 pageset format for any of thenonindex commands, however, improved performance will result if theDatabase Engine uses a compact sequential format instead. All workspaceand temporary databases used by the Database Engine are stored withrecords placed sequentially in memory. The final result can be stored ineither format.

C. The number of records in the database.

D. The format of the database, i.e., the number of fields, the type ofdata contained in the fields, and the maximum length.

As discussed above, the address of the predicate to be used duringcommand processing is passed to the Database Engine as part of thecommand block. The predicate is the Boolean equation which restricts theoutput records to a subset of the original database. It can be just oneterm or many and will preferably be expressed in a Reverse-Polishnotation to allow the Database Engine to process it more quickly. TheReverse-Polish notation removes any parentheses that exist in theoriginal SQL query, allowing the query to be processed sequentiallyusing a stack processor. For example, the following is a query in SQL:

    Select POSITION,MANAGER from EMPLOYEES

    where AGE<'25'

    and LOCATION='TRENTON'

    and VACATION<'10'

    and GRADE<'85';

The where clause is the predicate and can be converted to the followingReverse-Polish form:

    AGE,'25',<,

    LOCATION, 'TRENTON',=&

    VACATION,'10',<&,

    GRADE,'85',<&

It is the responsibility of the calling procedure to convert the SQLquery to this format before initiating the Database Engine operation. Itis also the responsibility of the calling program to replace the Englishlanguage names with the database and field number associated with eachbefore giving the predicate to the Database Engine.

The Database Engine can evaluate predicates on either character orinteger fields. Allowable arithmetic operations are equal, less than,greater than, less than or equal, greater than or equal, and not equal.These comparisons can be combined into more complex queries by using theBoolean operators OR, AND, and NOT. Any combination or integer orcharacter comparisons can be made with the above operators.

c. Processing Elements

As has been previously described, the five Database Engine elements workin concert to solve the problems at hand, taking advantage of theoverlap and pipelining of functions where possible. Again, by referenceto FIG. 3 they are:

1. Control Processor (DBCP) 310;

2. Working Store 312;

3. Predicate Evaluator (DBPE) 304;

4. Sort/Merge Unit (DBSM) 302;

5. Hash-code Generator (DBHG) 306; and,

6. Extractor/Memory Interface Unit (DBEM) 308.

d. The Control Processor

The Control Processor 310 (FIG. 3) is the only element whichcommunicates with the application and operating system programs that usethe Database Engine. It is the function of the Control Processor 310 toobtain all of the command and database information from memory, scheduleand control each of the other Database Engine elements, and tocommunicate status back to the calling programs. The complexity of thesefunctions requires a processor capable of computing addresses andcontrol information in parallel with the rest of the Database Engine.

The Control Processor 310 is preferably implemented using an an 801processor plus extensions for the Database Engine functions. It shouldbe understood that other conventional processor architectures could beused to perform the required processing functions, as long as they areprovided with interfaces to the Working Store buses 316, 318, thecontrol bus 320 and the computer system to which the Database Engine isattached.

The Control Processor 310 performs all of the command processing andcontrol functions in the Database Engine. These functions include thesetup and control of each functional element, as well as thedetermination of how the command is best processed. The following is alist of the functions that are performed by the Control Processor 310:

1. Reading the Database Engine command blocks from the system memory todetermine what functions are to be performed. Each command and the datadescriptor(s) associated with it is converted into a processing sequenceto be performed. For example, a sort command is executed by schedulingthe loading of blocks of the database into the Working Store 312, havingthe sort/merge unit 302 sort each block until the entire data base hasbeen sorted into many blocks, having the sort/merge unit 302 perform amerge of these blocks to create the final output records, and thenhaving the Extractor/Memory Interface Unit 308 write these records tothe system memory.

2. Fetching and evaluating the data descriptors to determine the formatof the data, how it should be accessed by the Extractor/Memory InterfaceUnit and in what order the columns should be extracted into the WorkingStore 312.

3. Fetching the predicate for each command and converting it into aprogram which the Predicate Evaluator will execute. The conversioncomprises converting column numbers to corresponding Working Storeoffsets (where the data is to be loaded by the extractor) and computingthe next instruction fields of each instruction. After creating thePredicate Evaluator program, the Predicate Evaluator instruction andconstant tables are loaded via the control bus 320.

4. Coordinating all of the other elements in the system. To perform thisfunction, the Control Processor 310 uses the control bus 320 to write tothe control registers in the other processing elements, to initiateprocessing, and to read the status of any of the processing elements.Each processing element can be controlled directly by the ControlProcessor 310 through the control bus 320. All communication betweenprocessing elements of the Database Engine is sent over the control bus320. The Control Processor 310 runs in parallel with the otherprocessing elements 302-308. This enables the control processor toperform processing in the background while the other elements areprocessing their data. The Control Processor 310 intervenes only when anelement needs a new block of data to process or has an error.

The functions of the Control Processor 310 can be performed withoutinterfering with the rest of the Database Engine processing elementssince the Control Processor 310 maintains all of the information itneeds for processing in an internal local working store 510 (FIG. 5A).The local Working Store 510 provides the space required to maintain allof the address and command data. Thus, once the command information isread, there is no further interaction with the system memory by theControl Processor 310.

The hardware structure of the Control Processor 310 is illustrated inFIG. 5A/5B. The Control Processor 310 is designed around an 801processor with a 64K byte microstore and a 32K byte local working store.Only a subset of the 801 instructions need be implemented since all (forexample, floating point) are not applicable to the Database Enginefunction. The Control Processor hardware includes the signalling andmaintenance interfaces to the rest of the system for the entire DatabaseEngine.

Turning now to FIG. 5, a Control Processor embodied using conventional801 architecture (less the floating point logic) is illustrated. TheControl Processor 310 includes a control bus input register (CBIR) 502which buffers data read from the control bus 320 to the ControlProcessor 310, and a control bus output register (CBOR) 504, whichbuffers data written to the control bus 320 from the Control Processor310. The Control Processor 310 is also provided with a storage datainput register (SDIR) 306 and a storage data output register (SDOR) 508.The storage data input register 506 and the storage data output register508 form the read and write buffers for the Working Store busses 316,318. The storage data input register 506 buffers data read from theWorking Store 312 to the Control Processor 310. The storage data outputregister 508 buffers data written from the Control Processor 310 to theWorking Store 312.

Internal storage for execution of operations and Control Processor datais provided by a local working store (LWS) 510. Data for the localworking store 510 is provided from any of the Working Store 312 or theControl Processor arithmetic logic unit 512 via the storage data inputregister 506. A control store 514 contains the control program that isexecuted by the control logic 516.

The control logic 516 provides sequencing and control for the ControlProcessor 310. The control logic 516 is a conventional microsequencerwhich includes an instruction register (IR) 518 and an instructioncounter (IC) 520. The instruction register 518 holds the currentlyexecuting instruction while the instruction counter 520 holds theaddress of the currently executing instruction.

The control processor includes 32 general purpose registers (GPR) 522for storage of operands and program data. In addition, three temporarysource registers 524-528 are provided for storing the operands of thecurrently executing instructions. The first temporary source register(RA) 524 is provided to temporarily store the first operand of thecurrently executing instruction. The second temporary source register(RB) 526 is provided to temporarily store the second operand of thecurrently executing instruction. The third temporary source register(RT) 528 is provided to temporarily store the second operand of thecurrently executing instruction as an input to the rotator 530 andAnd-Invert-Mask unit (AIM) 532. The third temporary source register (RT)328 also holds partial results for the multiply and other operations.

The arithmetic logic unit (ALU) 512 performs arithmetic and logicaloperations on the operands in the RA and RB registers 524, 526 undercontrol of the control logic 516. The address adder 534 receives theoperands from the RA and RB registers 524, 526, the current instructionfor the instruction register 518, the current instruction address fromthe instruction counter 520 and performs the address arithmetic forbranching instructions.

The rotator 530 is a barrel shifter for shifting the contents of the RTregister 528 right or left. The shifted result can be ANDed with theoutput of the mask generator 536 by the And-Invert-Mask unit 532.

The mask generator 536 receives its input from a starting addressregister (SAR) 540 and an ending address register (EAR) 542. The SAR 540and EAR 542 hold, respectively, the starting and ending bit address forthe mask generator 536, as supplied by the control logic 516.

The And-Invert-Mask unit (AIM) 532 performs rotating and maskingoperations on the contents of the RT register 528. One of the fourinputs to the AIM 532 is the multiply quotient (MQ) register 538. The MQregister 538 holds the partial product for the 801 engine's multiplystep instruction and is an operand for shift, rotate and storeinstructions.

The SIG, QBUS, INTRPT logic 538 provides the interface to the computersystem. It is through the SIG, QBUS, INTRPT logic 538 that the computersystem starts and terminates the operations of the Database Engine.

It should be understood that the above-described components are embodiedin a conventional 801 engine. The paths to the Working Store busses 316,318 and the control bus 320 have been added. The interface to the thecomputer system is of the conventional type embodied in the 801 engine.The 801 engine is described in more detail in the article THE 801MINICOMPUTER, author: George Radin, 1982 ACM 0-89791-066-4 82/03/0039,which is incorporated by reference herein, in its entirety.

e. The Working Store

The Working Store 312 (FIG. 3) preferably comprises at least 128K bytesof memory that is used to hold data while it is being processed by theDatabase Engine. The Working Store 312 is simultaneously accessible astwo equal partitions via two quadword (16 byte) busses 316, 318. Readand write both take one cycle, thus the Working Store 312 is capable of2 quadword accesses (read or write) per cycle. It should be understoodthat 128K bytes is the minimum preferable size. A larger size WorkingStore is even more preferable as cost and design constraints permit.Less preferably, smaller amounts of memory could be provided.

The Working Store 312 is directly addressable by all elements of theDatabase Engine system using the two quadword busses 316, 318. Each bushas 16 bytes of data plus parity and 16 bits of address and controlsignals. Thus each bus is 176 lines for a total of 352 lines.

f. Predicate Evaluator

The structure and operation of the Predicate Evaluator (DBPE) 304 willnow be discussed with reference to FIGS. 3 and 6A/6B. The PredicateEvaluator 304 is a special purpose processing element that can perform acomparison of two quadwords (16-byte) of data in the Working Store 312in two cycles or a comparison of a constant and a quadword of WorkingStore 312 in one cycle. The Predicate Evaluator 304 is a stack processorin that uses a boolean stack to process the reverse polish predicatesthat are created by the Control Processor 310. Instructions are loadedinto an instruction table 602 by the Control Processor 310 via thecontrol bus 320. The Predicate Evaluator 304 executes the instructionsin a looping fashion until its count of records is exhausted.

The Predicate Evaluator 304 provides fast processing of search and joinqueries for several reasons. It can compare a two quadword operands fromthe Working Store 312 every two cycles. Search keys longer than aquadword are compared a quadword at a time. Further, the searchexecution process is overlapped with the memory access process.Specifically, the Extractor 308 writes into one partition of WorkingStore 312 while the Predicate Evaluator 304 processes data out of theother partition. Finally, the Predicate Evaluator instructions contain a"next field" which allows an early exit out of the current predicateterm or out of the entire predicate if the current results uniquelydefine the search outcome. For example, when the first term of asequence of AND terms is false, the other terms need not be evaluated.The result is false regardless of what they are.

The Predicate Evaluator 304 performs comparisons of quadword operandsand uses a stack 632 to hold temporary results. It accesses the WorkingStore 312 through the Working Store busses 316, 318. Record operands arefetched from the Working Store 312, constants are fetched from theconstant table, and the results are written back to the Working Store312.

The constant table (CT) 604 is an array of constant quadwords used tohold comparison constants and Working Store addresses. The constanttable 604 is read into the comparator 630 a quadword at a time forcomparison operations. For address constants, only the least significant16 bits are used out of a quadword. The constant table 604 is writtenone doubleword at a time by the Control Processor 310. The constanttable 604 is initialized by the Control Processor 310 using the controlbus 320. A representative size for the constant table is 2K deep by 128bits wide.

The Instruction table 602 is a doubleword array of instructions that isloaded by the Control Processor 310 with the search program to beexecuted. The instruction table 602 is addressed by an instructioncounter (IC) 606 and instructions are read into the instruction register(IR) 608. A representative size for the instruction table is 2K deep by64 bits wide.

The Instruction Register (IR) 608 is a doubleword register which holdsthe instruction during execution. It has the following subfields:

    ______________________________________                                        A, B, D   Offsets from the Base A, B, and D                                             registers, respectively, for the operand                                      fetch address from Working Store or the                                       destination address for the result (D).                                       The A, B and D fields can also specify a                                      constant table address.                                             C         Instruction type field.                                             F         Flags. This field contains flag bits which                                    control the operation, the post-ANDing or                                     post-ORing of the stack, the looping for                                      longer than doubleword comparisons, and the                                   next field branching.                                               Next      This field (N0, N1) specifies an instruc-                                     tion address to be branched to if the                                         result of this instruction is either true                                     or false. The choice is specified in the F                                    field. The next field allows the Predicate                                    Evaluator to identify when a query is                                         resolved early and to take a branch around                                    the instructions that do not need to be                                       executed. This saves execution time and                                       improves performance. Due to the pipeline                                     length and the two cycle delay caused by                                      taking a next field branch, the next field                                    branches only result in improved perfor-                                      mance if the instructions are greater than                                    two instructions apart, otherwise the next                                    field should not be used.                                           ______________________________________                                    

The I-Adder 610 is a binary adder that updates the instruction counter606 by incrementing by 1, adding the next field from the instructionregister (provided via a mux 612), or resetting to zero. The instructioncounter 606 can be reset to any address by the control processor 310 viathe control bus 320. A representative size for the adder is 11 bits.

The predicate evaluator includes three Base Registers BASE-A 614, BASE-B616, and BASE-D 618. The base registers are used to save the baseaddress in the Working Store 312 of the A and B operands, and the resultdestination (D). Operand fetches are performed by adding offsets tothese registers to create the Working Store address.

Also provided are two length registers, LEN-A 620 and LEN-B 622. Thelength registers are loaded by the instructions with the number ofquadwords to be compared (i.e., the length of the operand) anddecremented in a looping fashion until they become zero, indicating thatthe comparison is complete. A record count register 624 contains thenumber of records to be processed.

Two 16-bit adders (designated together by reference numeral 626) areused to update the length, base, and/or record count registers duringinstruction execution. These adders 626 also produce zero conditionflags that can be tested to identify zero length or record countconditions. The output of the adders are provided to an output register628. The output register 628 is a staging register for data to bewritten to the Working Store 312 (FIG. 3) from the Predicate Evaluator304. The Predicate Evaluator 304 will write pointers to selected recordsback to the Working Store 312 so that they can be used by otherprocessing elements.

The comparator 630 is a three input comparator that compares twoquadwords and then compares the boolean result to the top-of-stack (TOS)from the stack 632. The top-of-stack is effectively popped and then theresult is pushed on the stack. Operands for the comparator 630 areprovided by the A and B Registers 634, 636. The A register (A-REG) 634and the B register (B-REG) 636 are loaded from the Working Store 312 forevery instruction, except instructions that compare the A register 634to an address contained in the constant table 604 do not load the Bregister 636.

The comparator 630 can perform the following comparisons of the A and Bregister (or constant table) values: greater than, less than, less thanor equal, greater than or equal, equal, and not equal. In addition itcan perform the following Boolean operations: AND, OR, and NOT on eitherthe result of the A/B register (or constant table) comparison and theTOS or the two top elements of the stack. In the first case the TOS ispopped then the result pushed on the stack, in the latter case both topelements are popped and the result is pushed on the stack. The resultingvalue is also sent to the control and sequencing logic 634 to determineif a next branch is to be taken.

The stack 632 is a 1-bit wide, last in/first out stack that is used tohold temporary values during processing of the query. The two topelements are available to the comparator 630 for processing at any time.

The control and sequencing logic 638 is a conventional microsequencerwhich controls the sequencing and branching of operations within thePredicate Evaluator 304. The Predicate Evaluator 304 preferably uses a 3cycle pipeline that runs at either one or two cycles per instructioninitiation.

The Predicate Evaluator 304 instruction set comprises nine instructiontypes:

1. Compare then AND with the top-of-stack (TOS). The two operands,either the A and B registers 634, 636 or the A register 634 and aconstant front the constant table 604 are compared and the result isANDed with the TOS value. The boolean result of this operation is pushedon to the stack 632 in place of the previous TOS value. Valid comparisonoperators are greater-than, less-than, less-than or equal, greater thanor equal, equal, and not equal.

2. Compare then OR with the top-of-stack (TOS). The two operands, eitherthe A and B registers 634, 636 or the A register 634 and a constant fromthe constant table 604 are compared and the result is ORed with the TOSvalue. The boolean result of this operation is pushed onto the stack 632in place of the previous TOS value. Valid comparison operations aregreater-than, less-than, less-than or equal, greater than or equal,equal, and not equal.

3. Compare and push on stack. The A and B registers 634, 636 or the Aregister 634 and a constant from the constant table 604 are compared andthe boolean result is pushed on the stack 632. Valid comparisonoperators are greater-than, less-than, less-than or equal, greater thanor equal, equal, and not equal.

4. Add or subtract. Two operands are either added or subtracted by theadder 626 and the result is stored in the identified destinationregister. Valid source operands are the Base A/B, Length A/B, the RecordCount, Base D, and the Constant (from the constant table 604). Theresult can go to any of the above and also to the output register 628.Add and subtract set a condition flag in the control and sequencinglogic 638, indicating when the result is zero.

5. Working Store access instructions: readws and writews. Readws putsthe data into either the A or B register 634, 636. Writews writes thevalue in the output register 628 to the Working Store address specified.The address is generated from any of the base registers.

6. Stack operations: push and pop. These instructions push a value onthe stack or pop a value off of the stack 632.

7. Stack logical operations: AND, OR, and NOT. The top two elements ofthe stack 632 can be ANDed or ORed by the comparator 630 and the resultpushed onto the stack in their place. The NOT TOS instruction invertsthe TOS.

8. Restart. The Restart instruction branches back to the beginningaddress of the program and resets the stack pointer to zero (emptystack) and increments the base A and B registers. This instruction isused after a record has been searched and starts the evaluation of thenext record. The record count and the Base-D registers 624, 618 areupdated prior to the execution of this instruction.

9. Stop and send status. This instruction halts the execution of thePredicate Evaluator 304 and sends a status word to the Control Processor310. The status word contains flags and information from theinstruction. It is used to tell the control processor that the PredicateEvaluator is done processing a block of records, that the output area isfull, or that an error has occurred.

Predicate Evaluator instructions perform three types of functions,updating pointers in the Predicate Evaluator 304, comparing operands,and writing results to the Working Store 312. Pointers are maintained inthe BASE A and BASE B registers 614, 616 for each of the records thatare to be compared, and are updated each time a record is processed.Records are stored in the Working Store 312 in sequential order, and thepointer provides a base address for a record, with the offset field inthe instruction pointing to the column in the record that is to becompared. Results are written back in Working Store 312 at the addressgiven by the destination (BASE D) register 618. The BASE D register 618is also updated each time a result is generated. The BASE A, BASE B andBASE D registers are incremented by the length A/B registers 620, 622,or constants within the constant table 604.

Instructions are fetched out of the instruction table 602 into theinstruction register (IR) 606. The instruction fetch and decode takesone cycle, after which there is a one or two cycle operand fetch, andfinally the execution takes one cycle. Thus the execution pipeline isthree cycles long, with instructions initiated every one or two cycles.Instructions that have two Working Store operands take two cycles forthe operand fetch phase and thus require two cycles between initiations.Instructions that have a Working Store operand and a constant tableoperand take only one cycle for the operand read since both can be readin parallel, thus these instructions can be initiated every cycle.

The program stored in the instruction table 602 is created by thecontrol processor 310 from the query predicate given with the command.It is a translation of the predicate that takes into account where inthe Working Store 312 the records are stored and their format. Ingeneral, the query processing follows the following scheme:

1. The Control Processor 310 reads the command, data descriptors, andpredicate to be executed and decides how the records are to be stored inWorking Store 312 for evaluation. The records are extracted so that thecolumns of interest are placed together within the record to facilitatecomparisons. The Control Processor 310 initiates the storage accessesand extraction operations to load the first block of records into theWorking Store 312.

2. While the first block is being loaded the Control Processor 310translates the predicate into the Predicate Evaluator program, using theformat of the records in the Working Store 312 and the required fieldsas a guide. It then evaluates the program and sets the next fields sothat the Predicate Evaluator 304 can take the "early exit" from thepredicate when possible.

3. Once the program has been created it is loaded into the PredicateEvaluator instruction table 602. Any constants that are needed areloaded into the constant table 604. Finally, all of the base, length,and count registers 614-624 are loaded with values that point to thecorrect locations in the Working Store 312. This is all done through thecontrol bus 320 while the Working Store 312 is being loaded with thefirst block of records.

4. Once the first block is loaded, the Control Processor 310 tells thePredicate Evaluator 304 to start processing it. Meanwhile, theExtractor/Memory Interface Unit 308 is setup to load the next block ofrecords in the opposite partition of Working Store 312. This loadingoperation is started to run in parallel with the processing of the firstblock by the Predicate Evaluator 304. Processing continues in thisfashion until the search is completed, the output area in Working Storebecomes full and must be written back to memory, or an error occurs.

5. When the search is completed the Extractor/Memory Interface Unit 308is instructed to write any remaining result records to the system memoryand the operation terminates.

g. Sort/Merge Unit

The Sort/Merge unit (DBSM) 302 performs the operations of sorting,merging, and joining. Additionally, the Sort/Merge unit performs the setoperations of union, intersection, difference, and cross-product onlists of keys. The similarity of these operations allows them to beperformed in the same hardware element efficiently. All of theoperations access the Working Store 312 (FIG. 3) exclusively, processingblocks of data that are loaded from the system's main or page storage410, 412 (FIG. 4). This reduces the load on the system storage andprovides one cycle access to keys.

The Sort/Merge Unit hardware will be better understood by reference toFIG. 7. Sort and merge operations are performed using a comparator 702(the key comparator) that compares two quadword (16 byte) operands fromthe Working Store 312 each read cycle. Each of the two operands entersthe comparator 702 by way of one of the two Working Store busses 316,318. Preferably, each operand comes from a different one of the twoindependently addressable Working Store partitions. This configurationfurther accelerates the sort operations by enabling concurrent access toboth operands.

The key comparator 702 produces a 2 bit result that identifies theresult of the comparison as being an "equal to", "less than", or"greater than" condition. The 2 bit result is sent to the control andsequencing logic 704, the operation of which will be described later.

The Working Store addresses for the two operands to be compared areheld, respectively, in the BASE A and BASE B registers 706, 708. Theaddresses A,B of the two operands are obtained from an internal memory710 which comprises two independently addressable memory arrays (pointerarrays) 712, 714. The pointer arrays 712, 714 are loaded by way of adata bus 716, with the Working Store addresses of the operands. Thepointer arrays 712, 714 are independently addressable by addressesprovided from the control and sequencing logic 704, respectively by wayof a first address bus 718 and a second address bus 720. The WorkingStore addresses are obtained from the extractor portion of theextractor/memory interface unit 308 (FIG. 3).

In order to provide for more efficient fetching of operands, the addressof the subsequent key is read from the pointer arrays 712, 714 in thesame read cycle as the base key address. The subsequent key addressesare stored within the BASE A and BASE B registers 706, 708 along withthe current (base) key addresses. In order to enable comparisons ofmultiple quadword keys, the BASE A and and BASE B addresses are loadedinto the A and B address counters 719, 721 respectively. The A and Baddress counters 719, 721 can be incremented by the control logic 704,one quadword address at a time in order to address the keys in quadwordsize portions. Thus, multiple quadword keys can be compared by thecomparator 702, one quadword at a time. In the embodiment of FIG. 7, theA and B addresses are provided to the Working Store 312 by way of theoutputs of the A and B address counters 719, 721, respectively. Wheremultiple quadword keys are not contemplated, the BASE A and BASE Bregisters can be used to address the Working Store directly 312.

In order to keep track of the addresses of pertinent data, the sort andmerge unit uses a number of pointers. During each pass of the sortoperation one of the pointer arrays is assigned as a source (READ)array, while the second is assigned as a destination (WRITE) array. Thei and j pointers, generated respectively by the i counter 722 and the jcounter 724, provide addressing for the source array. The k pointer,generated by the k counter 726, provides addressing for the destinationarray. The m counter 727, is used to keep track of base node addressesfor tournament tree merge sorting (explained in more detail infra). Thei, j and k and m counters 722-727 are loaded with an initial value bythe control processor 310 (FIG. 3) by way of the control and sequencinglogic 704. Each of the counters 720-726 can be incremented by thecontrol and sequencing logic 704.

The sort/merge unit operates by processing the keys as groups of listsand performing binary merge/sorts on two lists at a time. The q and rpointers, generated respectively by the q counter 728 and the r counter730, keep track of the remaining number of elements in each of the twolists. The q and r counters 728, 730 are loaded with an initial value bythe control and sequencing logic 504 and can be decremented under by thecontrol and sequencing logic 704. First and second comparators (the q/0and r/0 comparators) 732, 734 are connected to receive, respectively,the outputs of the q and r counters. The comparators 732, 734 detectwhen each of the q and r counters have been decremented to zero. Each ofthe comparators 732, 734 is of the type which produces a one bit binaryoutput which identifies the result of the comparison as being an "equalto" or a "not equal to" condition. The results of the comparisons aresent to the control and sequencing logic 704.

The initial length of the two lists to be merged p is provided by thecontrol processor 310, via the control bus 320, and held in the pregister 736. The initial number of keys to be sorted n is also providedby the control processor 310 and held in the n register 738. A thirdcomparator (the j/n comparator) 740 compares the value of the j pointer(from the j counter 724) with the value of n (from the n register 738)and informs the control and sequencing logic 704 when j>n. Similarly, afourth comparator (the k/n comparator) 742 compares the value of the kpointer (from the k counter 726) with the value of n (from the nregister 738) and informs the control and sequencing logic when k>n. Thethird and fourth comparators 740, 742 are of the two bit output typethat report the comparison results as being any of "equal to", "greaterthan" or "less than". A fifth comparator 743 compares the value in thep-register 736 with the value in the n register 738 and produces a onebit result which indicates whether or not p>=n.

The control and sequencing logic 704 sequences all of the adders,comparators, and pointer arrays in the Sort/Merge Unit 302. Controlalgorithms (described in more detail below) are similar for each of theoperations performed, but require different sequences. It is a functionof the control and sequencing logic 704 to coordinate all of theelements.

The control and sequencing logic 704 is preferably embodied as aprogrammable logic array designed to implement the sort/merge unitalgorithms (described below). Alternatively, the control and sequencinglogic 704 can be embodied as conventional microprocessor which performsthe sort/merge unit algorithms using the above-described hardware, undercontrol of a microcode program.

The operation of the control and sequencing logic 704 and the sort/mergeunit in general will be better understood by way of an example. FIG. 8illustrates an example of an ascending block sort (binary merge/sort) oneight keys (E,H,D,C,A,F,B,G).

During the first pass of the block sort, the keys are processed as eightlists 802-816, each having a length of 1 key. A comparison is performedon each pair of keys, (E,H D,C A,F B,G). As a result of the comparisons,the 8 original keys are placed into four new lists of two keys each818-824. Each of the four lists comprises the comparison "winner"preceding the comparison "loser", i.e. E,H C,D A,F B,G.

After the first pass of the binary merge/sort is complete, a second passis performed. During the second pass, the four lists of two keys each818-824 are compared. In other words, list E,H is compared with list C,Dand list A,F is compared with list B,G. As each "winner" is determined,it is written into a new, merged list. As a result of the second pass ofcomparisons the keys are again reordered into two lists 826, 828 of fourkeys each, i.e. C,D,E,H and A,B,F,G.

After the second pass is complete, a third merge/sort pass is performedon the two lists 826, 828. Comparisons are performed on the two lists(i.e. C is compared to A, and A is the "winner" then C is compared to Band B is the "winner", etc.). As each winner is determined it is writteninto a final list 830. The final list 830, is a single list having alength of eight keys in ascending order, i.e. A,B,C,D,E,F,G. The numberof passes required to complete a binary merge/sort is equal to LOG2 ofthe number of keys to be sorted with resulting fractions rounded to thenext highest number.

In order to perform the above-described ascending sort operation thesort/merge unit operates in cooperation with the other functionalelements of the Database Engine. Initially, the control processor 310(FIG. 3) designates one of the pointer arrays (e.g. 712, FIG. 7) as thesource (READ) array. The other array (e.g. 714, FIG. 7) is initiallydesignated as the destination (WRITE) array. The Working Store 312, andthe READ array are respectively loaded with a number (n) of input keysand their corresponding Working Store addresses. The keys to be sortedare supplied to the Working Store 312 by the Extractor/Memory InterfaceUnit 308 (FIG. 3). The Extractor/Memory Interface Unit 308 reads recordsfrom the page storage 412 (FIG. 4), extracts the keys, and writes theminto the Working Store by way of the Working Store busses 316, 318 (FIG.3).

The initial state of the Working Store 312 for the ascending sortexample of FIG. 8 is illustrated in FIG. 9. Each key A-G is stored alongwith a record identification number (RID) which identifies the databaserecord from which the key originated. As the keys are written to theWorking Store 312, the corresponding Working Store addresses are writteninto the designated READ array. In FIG. 9, the first pointer array 712is initially designated as the READ array for the first pass of theblock sort. Reference numeral 712(1) designates the first pointer array712 in its initialized state for the first pass.

When the Working Store 312 and the source pointer array have beeninitialized, the Control Processor 310 issues a START ASCENDING SORT(SAS) command to the Sort/Merge Unit 302 by way of the control bus 320.In response to the SAS command, the control and sequencing logic 704executes the algorithm illustrated in FIG. 10. As used in FIG. 10, WS(A)and WS(B) refer, respectively, to the keys stored in addresses A and Bin the Working Store 312. Similarly, READ(i) and READ(j) refer,respectively, to the Working Store addresses stored in addresses i and jof the designated READ pointer array. WRITE(k) refers an address k inthe designated WRITE array.

The algorithm of FIG. 10 will now be explained by reference to theascending sort example of FIG. 9 and the sort/merge unit of FIG. 7. Instep 1002, the pointers are set as follows: the p register 736 is set tothe initial list length of 1; the i-counter 722 is set to 1, so that itpoints to the Working Store address 00 of the first key E of the firstlist; the j counter 724 is set to 2 (i.e. p+1), so that it points to theWorking Store address 08 of the first key H of the second list; the qand r counters 728, 730 are set to the initial list length (i.e. 1); andthe k counter 726 is set to point to the first address in the WRITEarray (initially 714(1)). When this has been accomplished the BASE Aregister 706 is loaded with READ(1) (which is 00), and the BASE Bregister 708 is set to READ(2) (which is 08).

In step 1004, the E key (WS(00)) is compared to the H key (WS(08)) atthe key comparator 702. The key comparator 702 in turn signals thecontrol and sequencing logic 704 that E is less than H. In response tothe "less than signal", the control and sequencing logic 704 performsthe operations of step 1006. Specifically, the address (00) of the E keyis written into the designated WRITE array 714(1) at address 1 (asspecified by the k counter 726); the i counter 722 is incremented to 2,the k counter 726 is incremented to 2, the q counter 728 is decrementedto 0 and the BASE A register 706 is set to READ(2), which is 08. Step1008 is then performed.

In step 1008, the k/n comparator 742 compares the WRITE pointer k fromthe k counter 726 to the total number of keys to be sorted n (as storedin the n register 738). Since in this case, the write pointer k is equalto 2 and the number of keys to be sorted n is equal to 8, the k/ncomparator reports a less than or equal to condition to the control andsequencing logic 704. Responsive to this condition, the control andsequencing logic 704 executes step 1010.

In step 1010, the control and sequencing logic 704 uses the output ofthe q/0 comparator 732 to determine if there are any elements remainingin the first list. Since the original list length p was 1, and since oneelement from the first list (i.e. key E) has already been compared, theremaining elements in the first list is equal to zero. In response tothe "equal to" condition from the q/0 comparator 732, the control andsequencing logic 704 executes step 1012.

In step 1012, the control and sequencing logic 704 reads the outputs ofthe j/n comparator 740 and the r/0 comparator 734 to determine if eitherthe remaining key count in the second list is equal to 0 (r=0) or thesecond list pointer (as determined by the j counter 724) is set at acount greater than the total number of keys to be sorted. Since thesecond list still includes the H key the value of the r counter 730 willbe equal to 1 and the r/0 comparator 734 will indicate to the controland sequencing logic 704 that r is not equal to 0. Similarly, since thesecond list pointer is still set to 2 (pointing to Working Store address08) and the list length n is equal to 8, the j/n comparator 740 willindicate the less than or equal to condition. Responsive to the presenceof both the j<=n condition and the r not equal to 0 condition (the nonpresence of j>n OR r=0), the control and sequencing logic 704 willexecute step 1014.

In step 1014, the Working Store address of the H key (B=08) is writteninto the designated WRITE array at the k pointer address designated bythe k counter 726. After this has been accomplished, the j counter 724is incremented to 3; the r-counter 730 is decremented to 0, the kcounter 726 (WRITE array address) is incremented to 3; and a Workingaddress B=10 for a key in the second list is read from the READ pointerarray at READ(2). The control and sequencing logic 704 then executesstep 1016.

In step 1016, the control and sequencing logic 704 uses the output ofthe k/n comparator 742 to determine whether the WRITE array address hasexceeded the number of keys to be sorted. Since the number of keys to besorted n is 8 and the WRITE array address is 3, the k/n comparator 742indicates a less than or equal to condition. Responsive to the less thanor equal to condition, the control and sequencing logic 704 againexecutes step 1012.

As with the previous execution of step 1012, the control and sequencinglogic 704 reads the outputs of the j/n comparator 740 and the r/0comparator 734 to determine if either the remaining key count in thesecond list is equal to 0 (r=0) or the second list pointer (asdetermined by the j counter 724) is set at a count greater than thetotal number of keys to be sorted. Since the H key from the second listhas now been written to the WRITE array, the value of the r counter willbe equal to 0 and the r/0 comparator 734 will indicate to the controland sequencing logic 704 that r is equal to 0. Responsive to thepresence of the r=0 condition, the control and sequencing logic 704executes step 1018.

In step 1018, the control and sequencing logic 704 sets up the pointersfor the merge/sort of the next two lists. In this example, the first twolists comprised the E and H keys. The next two lists therefore comprisethe D and C keys. In preparation for processing the next two lists, thei counter 722 is reinitialized with its present value plus the listlength (i=i+p). The i pointer will therefore be equal to 3 and willpoint to Working Store address 10 in the READ array 712(1). The jcounter 724 will be similarly reinitialized with the value of j+p. The jcounter 724 will therefore be equal to 4 and will point to Working Storeaddress 18 in the designated READ array 712(1). The q and r counters728, 730 will both be initialized to the list length of 1. The BASE Aregister 706 is then loaded with the address 10 of the D key (READ (3)),while the BASE B register 708 is loaded with the address 18 of the C key(READ(4)). The control and sequencing logic 704 then executes step 1020.

In step 1020, the control and sequencing logic 704 reads the output ofthe j/n comparator 740 to determine if the j list is empty. Since thetotal number of keys to be sorted is equal to 8 and since the j pointeris only equal to 4, the j/n comparator 740 will produce a less than orequal to result. Responsive to this result, the control and sequencinglogic 704 will again execute step 1004 for the new lists.

In the second iteration of step 1004, the D key (WS(10)) is compared tothe C key (WS(18)) at the key comparator 702. The key comparator 702 inturn signals the control and sequencing logic 704 that D is greater thanC. In response to the "greater than" signal, the control and sequencinglogic 704 performs the operations of step 1022.

It should be understood that steps 1022 through 1032 are executed in asimilar manner to steps 1006 through 1016. The actual manipulation ofthe counters and use of the comparators will be self evident from FIG.10. For example, in step 1022, the C key is written into the designatedWRITE array 714 at address 3 (as specified by the k counter 726); the jcounter 724 is then incremented to 5, the k counter 726 is incrementedto 4, the r counter 730 is decremented to 0 and the BASE B register 708is set to READ(5), which contains Working Store address 20. Later, as aresult of the execution of 1030, the D key is written into the WRITEpointer array 514(1) at address 4.

Steps 1004 through 1030 are repeated iteratively until all four pairs oflists E,H D,C A,F B,G have been merged and appear as shown in the WRITEpointer array 714(1) designated for the first pass.

The completion of the first pass is determined by one of steps 1016 or1032, depending on whether the merge of the last two keys results in theWS(a)<=WS(B) path to be taken or the WS(A)>WS(B) path. Since thecomparison of the last two keys B,G will result in the WS(A)<=WS(B) pathto be taken, the end of the first pass will be detected by step 1016.

After step 1014 is executed for the last element, the k counter 726 willbe set to 9. Since k=9 and the number of elements n=8, the k/ncomparator 742 will indicate that k is greater than n. Responsive tothis indication, the control and sequencing logic will execute step1034.

In step 1034, the counters and registers are reinitialized for thesecond pass of the binary merge sort. As will be observed from FIG. 9,the read and write arrays are swapped so that the second pointer array714(1) will now supply the Working Store address while the first pointerarray 712(2) will serve as a repository for the merged addresses.

In addition to the swapping of the designated READ and WRITE pointerarrays, the counters and registers are initialized as follows: the listlength p is doubled so that 4 lists of two keys each are formed (i.e.EH, CD, EF, BG); the j, q, and r counters are reinitialized based on theupdated list length so that j=3, q=2 and r=2; and the first list pointer(the i counter) is reset to 1. Finally, the BASE A register 706 isloaded with the Working Store address (00) of the first key E in thefirst list, while the BASE B register is loaded with the Working Storeaddress 18 of the first key C in the second list. Step 1036 is thenexecuted.

Step 1036 is executed to determine whether the sort is complete. Thecontrol and sequencing logic 704 compares the number of keys to besorted (the value in the n register 738) with the number of keys in eachlist (as held in the p register 736). In this case, since the listlength p=2 and the number of keys to be sorted is equal to 8, the sortis not complete. Upon determining that the sort is not complete, thecontrol and sequencing logic 704 again iteratively executes theappropriate ones of steps 1004 through 1032 until the last two keys Fand G in the last two lists have been compared and merged. As a resultof the second iteration of merges, the Working Store addresses arewritten into the WRITE pointer array as shown in reference numeral712(2).

When the second pass is complete (as determined by step 1032 since F>G)step 1034 is again executed. For the third and final pass 806, the READand WRITE arrays are again swapped so that 712(2) becomes the READ arrayand 714(2) becomes the WRITE array; the list length p is again doubledto 4 so that two lists of 4 are operated on, specifically, CDEH andABFG; and the counters and registers are set appropriately as indicatedin block 1034.

At the end of the third pass, the WRITE array 714(2) appears as shown inFIG. 9. After the third pass, step 1032 is executed one more time andthe list length p is set to 8.

The end of the sort operation is determined by step 1036. When the listlength p is greater than or equal to the total number of keys to besorted n, the sort is complete. The sort/merge unit informs the controlprocessor 310 of the sort completion by asserting a signal on thecontrol bus 320. When the control processor 310 receives the sortcomplete signal, it commands assembler function of the Extractor/MemoryInterface Unit 308 (FIG. 3) to move the records from the Working Store312 back into the system memory. Records are placed into the systemmemory in sorted format by the memory interface unit addressing the keysfrom Working Store in the order designated in the final WRITE pointerarray (e.g. FIG. 9, 714(2)).

As has been described, The sort function of the Sort/Merge Unit 702 ispreferably a hardware implementation of a binary merge sort. Binarymerge sort techniques are discussed in detail in the book Sorting andSort Systems by Harold Lorin, published by Addison-Wesley PublishingCompany, Inc., Library of Congress Catalog Card No. 73-2140, copyright1975, which is incorporated by reference as if printed in its full textbelow. The binary merge sort is performed on Working Store size blocksof keys at the rate of one quadword comparison per cycle. The number ofkeys contained in each block is dependent on the keylength.

Longer lists of keys are created by merging the sorted blocks. Merging,is the act of combining of two or more ordered lists into a singleordered list. The merge implemented is a hardware implementation of a128-way "tournament tree." using a replacement/selection algorithm. The128-way merge outputs a result every seventh cycle, performing aquadword compare every cycle in a 7 level tree. The structure andoperation of hardware tournament tree merge will be better understood byreference to FIGS. 7 and 12-14.

FIG. 12 is an illustration of a conventional 8-way tournament tree. Aneight way tournament tree has 15 nodes 1-15 and performs three levels ofcomparisons. Keys from eight lists to be merged enter the tree at itsbase (nodes 8-15). Winning keys advance upwards through the tree. Thewinner of the third level of comparison is taken from the tree at node 1and placed in the final merged list.

FIG. 13A is an illustration of the initialization of the Working Store312 and the pointers arrays 712, 714 by the Control Processor 310 forthe hardware tournament tree operation. Based upon the number of liststo be merged, the Control Processor calculates the width (number of basenodes) and the height (number of levels of comparison) of the tournamenttree. The width (m) of the tree is equal to the number of lists to bemerged rounded to the next highest power of 2. The number of levels ofcomparison (L) in the tree is equal to log₂ of of the width (m).

In the example of FIG. 13A, there are six lists 1302-1312 in WorkingStore 312. The lists 1302-1312 are brought into the Working Store 312 bythe Extractor/Memory Interface Unit 308 responsive to an initiationcommand from the Control Processor 310. Since there are six lists, theControl Processor 310 calculates the width (m) the tree as 8 and thenumber of levels of comparison (L) as 3 (log2 of 8). The ControlProcessor 310, therefore, logically partitions the pointer arrays 712,714 into 4 areas 1314-1320, one for each of the three levels ofcomparison and one for the base.

Initially, the Control Processor 310 loads the level of comparison areas1314-1318 of the pointer arrays 712, 714 with pointers to an automaticwinner 1322 (i.e. a key that can not loose to other keys during acompare). The base area 1320 is initially loaded with pointers to thefirst key from each input list 1302-1312 held in the Working Store 312.Empty lists are represented by a pointer to an automatic loser 1324 inthe corresponding position of the base area 1320. When theinitialization of the Working Store 312 and the pointer arrays 712, 714has been accomplished, the control and sequencing logic 704 of theSort/Merge Unit 302 begins the process of filling the tournament tree.

The fill tree process for an ascending merge using the eight way tree ofFIG. 12 is illustrated in FIG. 14A. The process of FIG. 14A comprises areplacement selection merge algorithm. Each of the variables describedin FIG. 14A is held in the hardware of the Sort/Merge Unit of FIG. 7.Specifically, the variables A and B correspond the Working Storeaddresses held, respectively, in the A and B address registers 719, 721;the variable i (used in the process of FIG. 14A to determine the parentnode) is held in the i counter 722; the variable m (used in the processof FIG. 14 to point to the base node) is held in the m counter 727; thevariable Looser is a temporary storage location (for which the pregister 736 can be utilized). As used in FIG. 14A, WS(n) refers to thecontents of location n of the Working Store 312, WRITE (n) refers to thecontents of location n of the designated WRITE pointer array, andREAD(n) refers to the contents of location n the designated read pointerarray.

In step 1402, the process variables are initialized and the READ andWRITE arrays are given their initial designations. As will be observedfrom FIG. 14A, pointer array 714 holding the base (nodes 8-15) isdesignated as the READ array and the pointer array 712 holding the levelabove the base (nodes 4-7) is designated as the WRITE array. Further,the width of the array, in this case 8, is set into the m counter 727and the starting parent node number INT(m/2)=4 is loaded into the icounter 722. This being accomplished, the A register 719 is loaded withthe Working Store address at READ(4) and the B register 721 is loadedwith the Working Store address at WRITE(8).

It will be observed that initially, READ(4) contains the Working Storeaddress (16) of an automatic winner while WRITE(8) contains the WorkingStore address (1) of the key "A". It should be understood that the nodesof the tournament tree as configured in the pointer arrays 712, 714 holdpointers to keys rather than the keys themselves.

In step 1404 the key at WS(A) is compared with the key at WS (B) by thecomparator 702. Thus the key "A" (at WS(1)) is compared with ahautomatic winner (at WS(16)). Responsive to a determination by thecomparator 302, that WS (A)<=WS (B) , the control and sequencing logic704 executes step 1406.

In step 1406, the node address (8) of the challenger is is stored in atemporary storage area called LOOSER (e.g. in the p register 736) andthe B register 721 is loaded with the address (4) of the parent node. Itwill be seen from FIG. 14A, that, alternatively, if WS(A)>WS(B) step1407 is executed, LOOSER is loaded with A and the contents of the Bregister are left intact. In any event, step 1408 is then executed.

In step 1408, the designations of the READ and WRITE pointer arrays areswapped and the comparison loser is written on to the tree. In otherwords, pointer array 714 becomes the READ array and pointer array 714becomes the WRITE array. In the present example, the Working Storeaddress (8) of the loser "A" is written on to the tree by loading itinto the WRITE array 714 at the address i (=4). The i counter is thenreloaded with INT(i/2) and step 1410 is executed.

In step 1410, the i value is compared with 0 to determine if the firstwinning key has been found. If i is not equal to 0, then step 1412 isexecuted.

In step 1412 the pointer content of the parent node at the next highestlevel is loaded into the A register 719. Since i=2, the A register isloaded with READ(2) which is the Working Store address (16) of the anautomatic winner. Step 1404 is then again executed and the keys at WS(A)and WS(B) are compared by the comparator 302. Since WS(16)=automaticwinner, then WS(A)<=WS(B) and steps 1406-1410 will again be executed.

From the foregoing, it will be apparent that steps 1404 through 1412 areexecuted iteratively until interrupted by a determination, in step 1410,that i=0. FIG. 13B illustrates the state of the pointer arrays 712, 714at the first detection of i=0 by step 1410.

When it is detected that i=0 step 1414 is executed to begin the loadingof the next key onto the tree. In step 1414, the base node address (m)is incremented by one, the parent node address (i) is set to INT(m/2),pointer array 712 is designated as the READ array and pointer array 714is designated as the WRITE array. Step 1416 is then executed.

In step 1416, the value of m is checked to determine if the fill treeprocess is complete. When the value of m is equal to twice the width ofthe tree (8×2=16 in this case) then the fill process is complete. Whenthe tree is filled, Working Store address B (the address of the firstwinner) is sent to the assembler function of the extractor/memoryinterface unit 308 and the base area is reloaded (by the extractorfunction) with the next key in the list from where the winneroriginated. The merge operation of FIG. 14B is then executed. If thefill process is not complete then step 1418 is executed.

In step 1418, the B register 721 is loaded with the Working Storeaddress in WRITE(m) and the A register 719 is loaded with the WorkingStore address from READ(i). Since m=9 and i=4 (INT(9/2)) then the Bregister is loaded with 3 (pointer array 714, address 9) and the Aregister is loaded with 1. Steps 1404-1412 are then again iterativelyexecuted for the key "C" represented by node 9.

As will be apparent from FIG. 14A, steps 1404-1418 are executediteratively until each of the base nodes has been loaded onto the tree,all of the automatic winners have been displaced, and the first winningkey is determined. FIG. 13C illustrates the state of the pointer arraysat the end of the fill tree process as determined by step 1416. As analternative to loading the base with the next element from the list ofthe winner after step 1416, the base can be backfilled during the fillprocess by loading the next element in a list as the preceding elementin that list advances onto the tree.

FIG. 14B is a flow chart illustrating the tournament tree operation.From FIG. 14B it will be apparent that the steps of the actual treeoperation 1422-1438 are similar to those of the fill tree process1402-1418. The primary difference between the two operations is in thedetermination of the comparison path. In the fill tree process of FIG.14A, the tree is filled from left to right across the base by using them pointer (as shown in step 1414). In contrast, during the treeoperation of FIG. 14B, the next key compared, and therefore the path ofcomparison, is determined by the previous winner. Since the extractorkeeps track of the winner's list of origin, the proper base startingpoint (i) is sent by the extractor each time a new winner is determined.As with FIG. 14A, all division in FIG. 14B is integer division, (i.e.only the integer portion of the result is examined).

During the tournament tree operation, if a list empties the extractorcan either stop the sort/merge unit or load an automatic loser onto thetree. Which option is selected depends on the type of merge beingexecuted.

Where the merge operation is intended to run until all lists are empty,then an automatic loser is loaded, Otherwise, the merge would bestopped. When an automatic loser becomes a winner (because the only keysleft on the tree are automatic losers) then the merge is complete. Wheretwo keys are equal, one can be arbitrarily chosen as the winner (e.g.the key from Working Store address A always wins over an equal key fromWorking Store address B).

Join operations are performed using the sort/merge join algorithm.Joining two tables requires that they are both in the same sorted order(e.g. ascending or descending) and that the columns on which the join isdefined are identically formatted. The sorted order depends on the joincriteria. When equal to, greater than, or not equal to criteria isspecified, ascending order is used. When less-than is the specifiedcriteria, a descending order is used. The lists are, therefore, firstsorted using the sort/merge unit 302 and then joined.

The join is executed by merging a first list L1 with a second list L2until the join criteria is met. When equal to, greater than, or notequal to criteria is specified, an ascending merge is performed. Whenthe less-than criteria is specified, a descending merge is performed.When the join criteria is met, the record ID of the corresponding keysare written as a pair to a result area of the Working Store 312. Oncethe key IDs have been written to the Working Store 312, the join iscontinued by stepping through the first list L1 one key at a time andcomparing to a window of keys in the second list L2. The window isdefined by all of the keys in the L2 list that meet the join criteriawhen compared to any one element of the L1 list. For key L1(i) there areL2(j) to L2(k) keys that match (where j is less than or equal to k).Matching keys have their record IDs written as a pair to the result areaof the Working Store 312. When the end of the window is reached (i.e.the join criteria is no longer met), the first list L1 list is steppedto L1(i+1), the second list L2 is reset to L2(j) (i.e. the beginning ofthe window). The join operation is then continued as a two way merge ofthe first and second lists until the join criteria is again met, atwhich point a new window is created.

A pseudocode embodiment of the join operation is illustrated below:

    ______________________________________                                        Two way merge L1(i);L2(j)                                                                        Perform two way merge.                                     On L1(i), L2(j) meet                                                                             If join criteria is met                                    selected join criteria                                                                           perform the following                                      (any of >,<,=,NE)  steps. Otherwise                                                              continue 2-way merge.                                      Output L1(i), L2(j)                                                                              Write L1(i), L2(j)                                                            record IDs to Working                                                         Store.                                                     k=j                Initialize pointers.                                       k=k+1              Increment window                                                              pointer.                                                   compare L1(i):L2(k)                                                                              Check if join criteria                                                        is met.                                                    if join criteria is met                                                       output L1(i), L2(k) and                                                       go to 40                                                                      i=i+1                                                                         Return to 5        Resume Merge                                               ______________________________________                                    

A more detailed description of sort/merge/join algorithms can be foundin C. J. Date, An Introduction to Database Systems, Addison-WesleyPublishing Company, Reading, Mass., 1983, the full text of which isincorporated by reference herein as if printed in full below.

The sort/merge unit 302 performs the initial comparison of the join.Other predicate terms are performed by the Predicate Evaluator 304 (FIG.3). For this reason, the most restrictive predicate in the join shouldbe performed by the Sort/Merge Unit 302, and the remainder performed bythe Predicate Evaluator 304. This method will result in the fastestprocessing and the smallest number of predicates being evaluated by thePredicate Evaluator 304. For multiple predicate joins the Sort/MergeUnit 302 evaluates the first predicate and then tells the PredicateEvaluator 304 to evaluate the remainder.

The set operations union, intersection, and difference are alsoperformed using the sort/merge algorithm. The difference between theseand the join operation is the way the output record is selected andconstructed. Join combines the two records into one record that containscolumns from both records. Set operations are defined only on databasesthat have the same format (i.e. the same number and types of columns).The outputs of the set operations union, difference, and intersectionhave the same format as the inputs. Cross product is the exception tothis rule. Since the cross product is essentially a unrestricted join,all records in one database are joined with all of the records in theother database.

The union operation creates an output table that contains one copy ofall of the unique records in the two input tables. That is, if thecomparison operation results in not-equal, both input table records arewritten. If the two input records are equal, then only one is written tothe output table (from either table). A pseudocode embodiment of theunion operation is illustrated below:

UNION OPERATION

COMPARE L1(i):L2(j)

IF L1(i)<L2(j), OUTPUT L1(i), i=i+1

IF L1(i)>L2(j), OUTPUT L2(j), j=j+1

IF L1(i)=L2(j), OUTPUT L1(i), i=i+1, j=j+1

CONTINUE

The intersection operation writes only one copy of the equal records,while the difference operation writes only the record from the A tablewhen the comparison is unequal. Thus, the difference between all threeset operations is which condition causes the output to be written.Pseudocode embodiments of the intersection and difference operations areillustrated below:

INTERSECTION OPERATION

COMPARE L1(i):L2(j)

IF L1(i)<L2(j), i=i+1

IF L1(i)>L2(j), j=j+1

IF L1(i)=L2(j), OUTPUT L1(i), i=i+1, j=j+1

CONTINUE

DIFFERENCE OPERATION

COMPARE L1(i):L2(j)

IF L1(i)<L2(j), OUTPUT L1(i), i=i+1

IF L1(i)>L2(j), j=j+1

IF L1(i)=L2(j), i=i+1, j=j+1

CONTINUE

A further improvement to the sort/merge Unit 102 applies hardwarecodeword techniques (also referred to as offset value coding) to aconventional replacement-selection type tournament sort, of the typedescribed in chapter 5.4 of Sorting and Sort Systems by Harold Lorin(previously incorporated by reference herein). The use of offset valuecoding reduces the number of bytes compared to determine the orderbetween keys.

The offset value coding hardware identifies the offset of the word inthe key where the comparison operation resulted in a difference from theprevious winning key. Each codeword comprises the offset and the word.Since codewords are always based on the previous winning key, thecodewords need only be compared to determine if a key is larger thananother key. If the keys are equal, then both keys are scanned further(from left to right) to determine where a difference exists or if thekeys are exactly equal.

A discussion of the application of offset value coding to replacementselection sorting can be found in IBM Technical Disclosure Bulletin ,Vol. 20, No. 7, December 1977, pp 2832-2837 which is in its entirety,incorporated by reference herein as if printed in full below.

The use of codeword comparisons (rather than direct key comparisons) hasthe advantage that the leftmost portion of the keys are only comparedonce during the sort process. This is so, because the codeword maintainsthe position of the difference from the last comparison operation. Thus,a minimum number of compares is performed, improving performance overalgorithms which must compare the leading words of the keys during everykey compare.

FIG. 11 shows an embodiment of the sort/merge unit which uses additionalhardware to apply codeword techniques to a replacement/selection typetournament sort. It should be understood that the hardware of FIG. 11 isused as an addition to the hardware of FIG. 7.

In order to implement codeword techniques, two 8K by 4-bit offset arrays1102, 1104 are provided which are concatenated with the pointer arrays702, 704 of the Sort/Merge Unit embodiment of FIG. 7. The codewordtournament tree sort hardware of FIG. 11 also includes Base A and Base Boffset registers 1106, 1109 which complement the A and B addressregisters 706,708 in the embodiment of FIG. 7. In addition to holdingthe address of the offset for the current key, the BASE A and BASE Baddress registers have provision for storing, in the same read cycle asthe A and B base offsets, the A+1, B+1 offsets (i.e. the offsets of thenext two keys to be compared).

A and B offset address counters 1110, 1112 contain the Offset Arrayaddress for the codeword of the current keys being compared. The the Aand B offset address counters 1110, 1112 are loaded with the base keyaddresses from the BASE A Offset and BASE B Offset registers 1106, 1109and are incremented by one quadword address at a time in order tocompare the offsets of quadword size sections of multiquadword keys. Itshould be understood that this feature is used since the Working Store312 (in the preferred embodiment) is accessed in quadwords, whereas keyscan be larger than a quadword.

A and B Offset Registers 1114, 1116 contain the offset of the currentkeys (or quadword size key sections) being compared. These offsets arecompared by a comparator 1118 which informs the control logic whetherthe two keys differ. Where the offsets are not equal, the higher valueoffset will win and it will not be necessary to compare the keys. Wherethe offsets are equal the quadwords of the two keys addressed by theoffsets are compared to determine the winner. If the two quadwordscompared are equal (in a multiquadword key), the control and sequencinglogic 704 will increment the A and B offset counters so as to cause thenext two quadwords of the corresponding keys to be compared. Thesequencing logic 704 will continue to increment the A and B offsetcounters until the corresponding quadword key compare determines awinner.

The embodiment of FIG. 11 also includes two multibit adders 1120, 1122.The adders 1120, 1122 add the offsets to the A and B addresses so thatthe keys can be compared at the point of offset.

h. Hash Generator

The hash generator (DBHG) 306 is a hardware element that takes 8 bytekeys and creates a hash code from their contents. The hash code is a9-bit value that is created by adding 8 sub-codes. The hash codegenerator is used for the EQUIJOIN processing, because similar keys willbe lumped into the same hash-code value bucket. By lumping. similar keysinto buckets, the hash-code join algorithm narrows the scope of the joinalgorithm discussed earlier, since the sort/merge join algorithm onlyneeds to be performed on each hash code bucket. Hashing and hash codesare discussed in detail in the book THE ART OF COMPUTER PROGRAMMING,Volume 3, Sorting And Searching, by Donald E. Knuth, Published byAddison-Wesley Publishing Company (copyright 1973), which isincorporated by reference in its entirety as if printed in full below.

To perform the hash code version of the EQUIJOIN, both tables must behashed to create buckets for each code. A bucket is a group of keys forwhich the application of hashing has resulted in the same value. Oncethe hashing of the keys in both tables is done, the identical bucketsfrom both tables are sorted by key, then joined as discussed earlier. Inmost cases, hashing the tables results in hash-code buckets that areless than the size of the Working Store 312. These tables can then beloaded into WS, sorted, and joined without any further system memoryaccesses. Thus, the number of memory operations is reduced because themerge step of the sort is not required on these hash-code buckets. Theperformance of the EQUIJOIN is improved significantly due to thereduction in system memory accesses.

The DBHG hardware will be described with reference to FIG. 15. The DBHGhardware includes a 256×8 look-up table 1502 of 9-bit hash code valuesand an eight input adder 1504. There is one 256 element array of codesfor each byte in the input key. The input key, held in a register 1506,indexes the array 1502, resulting in one of the 256 codes beingselected. The sum of the 8 codes generated in this way is the hash-codebucket number for this key. The key is written to this bucket and thenthe next key is read.

Longer keys are handled by dividing the key into 8-byte long subkeys andgenerating a hash code for each subkey. All subkey hash codes are addedtogether to form the final hash code. In order to accommodate keyslonger than 8 bytes, the Hash Code Generator 306 is provided with a keyaddress register 1508, a length register 1510, an adder 1512 and a saveregister 1514. Prior to the commencement of hashing, the save register1514 is initialized to zero and the length register is loaded with thesubkey length (8 bytes in the embodiment of FIG. 15).

When a key is to be hashed, its base Working Store address is loadedinto the key address register 1508. The first eight bytes of the key arethen loaded into the key register 1506. The resulting hash code is heldin the save register 1514. Once the first eight byte portion of the keyhas been processed, the subkey length is added to the base address bythe adder 1512 and the next eight byte subkey is read from the WorkingStore 312 and processed. This procedure is performed iteratively untilthe hash codes have been generated for each eight byte subkey.

The resulting hash codes from each subkey are added, cumulatively asthey are generated, in the save register 1514. At the end of the hashingoperation for all of the subkeys, the save register 1514 will containthe hash code for the complete key.

Once all of the keys from both tables have been lumped into hash-codebuckets, then each bucket is joined using the sort/merge join algorithm.

All of these operations are performed by the Hash-Code Generator 306,the Extractor/Memory Interface Unit 308, and the Control Processor 310.The Hash-Code Generator 308 maintains mappings for the 256 hash codebuckets and the two input tables. Tables are read in as blocks, thenhashed, and written out by giving the Extractor/Memory Interface Unit308 the hash-code bucket and the key. A mapping table in theextractor/memory interface unit 322 keeps track of where the bucket islocated in system memory and how to increment the location once thestore is complete. Thus, the entire hashing operation can execute withonly minimal intervention of the control processor 310.

Once the hashing is complete, the Control Processor initiates asort/merge join on each of the buckets. Each pair of buckets (one fromeach of the two input tables that have the same hash-Code) is fetchedfrom system memory to the Working Store 312 and then the Sort/Merge Unit302 is setup and started to perform the sort/merge join. The sort/mergejoin executes as before, although it has smaller tables to join thanbefore.

The following is the sequence of operation of the hash join:

1. Fetch a block of records from Table A.

2. While the next block is being fetched, hash the previous block andthen write each record to its appropriate hash-code bucket.

3. Repeat steps 1 and 2 until the entire Table A has been hashed.

4. Do steps 1, 2 and 3 for Table B.

5. Set i equal to zero.

6. Perform the sort/merge join algorithm on HA(i) and HB (i) .

7. Increment i by 1 and go back to step 6 if i=256.

8. Done.

i. Extractor/Memory Interface Unit

The extractor/memory Interface Unit (DBEM) 308 (FIG. 3) is the componentof the Database Engine which fetches and stores data from/to systemmemory (main storage 410 or page storage 412; FIG. 4). Theextractor/memory interface unit 308 has two primary functions: theextraction/ assembling of fields from the data being fetched/stored intosystem memory, and the maintenance of the mapping information for thelists of records used during sorting and merging operations.

In sorting and database applications, the sort key or field on which asearch is defined are often spread throughout the records and must beextracted into a useable format before the operation can proceed. Forsorting this means getting each key field an concatenating them inprecedence order so that they can be treated as one large key. Fordatabase processing, the columns of a table that are being searched orselected must be extracted from the rows so that they can be processed.

Field extraction is done for several reasons in sorting and databaseprocessing. Among these reasons are:

1. To create a usable sort key by combining the primary and secondarykey field into one key.

2. Needed fields are extracted so that only the fields required for thesort, search, and output generation are carried. Removing unneededfields reduces both the memory traffic and the amount if memory used forthe operation.

3. To pick subsets of fields so that pattern matching can be performedmore easily.

4. To put fields in correct order for the output phase of theprocessing, which may conflict with the key order or require a differentset of fields than the search or sort itself. This function is sometimescalled field assembly, although it is essentially the same as theextraction function.

In many conventional software applications, the extraction function isperformed by a series of "Move Character Long" or MVCL instructions. OneMVCL is typically performed for each field in the record that is to beextracted. The fields are all brought together in their extracted formbefore the actual search or sort occurs. Moving all the data isinefficient because of the amount of storage accesses that occur. Inaddition to the pre-extraction memory accesses, the extracted fields areconventionally re-fetched to perform the sort or search operation. Ifthe fields could be extracted and sorted (or searched) in one operationthe performance would be greatly improved because the number of memoryaccesses would be halved.

To get data from records created by DB2 into a more efficiently comparedform, the extraction function of the Extractor/Memory Interface Unit 308reorders the fields as they are fetched into a compact form. Theextraction process causes fields to be oriented in the Working Store 312(FIG. 3) with fixed length and stride.

The mapping function of the extractor/memory interface unit 308 uses aof entries (mapping table) comprising Working Store addresses, lengths,counts, and system memory addresses. Each of the lists being fetchedduring an N-way merge or a sort operation have a entry in the mappingtable. When the sort/merge unit 302 wants a new entry from a list, itsends the Extractor/Memory Interface Unit 308 the ID number of the listhaving the entry. The Extractor/Memory Interface Unit 308 takes this IDnumber and looks it up in the mapping table to find out all theinformation needed to fetch the field, including the extractioninformation. The same format is also used for output records, aread/write (R/W) flag indicates the direction of transfer.

The structure and operation of the extractor/memory interface unit willbe better understood by reference to FIG. 16. The Extractor/MemoryInterface Unit includes a memory buffer 1602, a Working Store buffer1604, a crosspoint switch 1606, a mapping table 1608 and a memoryinterface 1610 which interfaces with the system memory (main Store 410and page storage 412; FIG. 4) via the system memory bus 322. As recordsare fetched from the system memory (via the memory interface 1610), theyare loaded into the memory buffer 1602 and written into the WorkingStore buffer 1604 (via the crosspoint switch 1606) a quadword at a time.Each quadword is then transferred in its extracted format into the theWorking Store 312 (FIG. 3) for processing.

The reverse process happens on the Working Store to system memoryoperations. During Working Store to system memory operations, fields areassembled from the Working store buffer 1604 using the crosspoint switch1606 and written into the system memory.

During merge operations the entries in the mapping table 1608 eachcontain main memory/Working Store address pairs, key lengths, and countsof each list being merged so that the Control Processor 310 does nothave to be involved in the fetch process. When the Sort/Merge unit 302needs another element from a list, it informs the Extractor/MemoryInterface Unit 308 (via the control bus 320, FIG. 3) which list ID tofetch the key from. The Extractor/Memory Interface Unit 308 reads theappropriate mapping table entry to determine where the list is stored inmain memory and fetches it accordingly. The fetch process can occurconcurrently with the sort/merge that is being processed out of theWorking Store 312, stealing cycles on the Working Store bus 316, 318when a Working Store access is required.

FIG. 17A/17B are top and bottom halves of a more detailed diagram of anembodiment of the Extractor/Memory Interface Unit 308. As previouslydescribed, the Extractor/Memory Interface unit 308 includes a mappingtable 1702. The mapping table 1702 (which corresponds to the mappingtable 1608 of FIG. 16) is a table of information which maps systemmemory addresses to Working Store addresses. The mapping table 1702includes one entry for each record to be processed by the databaseengine 300. The mapping table 1702 is loaded at the beginning of arequest by the Control Processor 310 and updated each time a record istransferred. The mapping table 1702 is reloaded by the Control Processor310 as needed.

The crosspoint switch 1704 (which corresponds to the crosspoint switch1608 of FIG. 16) provides for the reordering of bytes during thetransfer of data. The crosspoint switch 1704 assembles the bytes intorecords under the control of the control logic 1706 (described later).

The request queue 1708 stages requests for transfers until a currentlyexecuting transfer is complete. The request queue 1708 is loaded by theother processing elements in the Database Engine 300 and is emptied astheir requests are processed by the extractor/memory interface unit 308.Each element in the request queue 1708 includes a map table entryidentification number (ID) 1710, the number of records requested (A)1712, and a list number (L) 1714 which is returned to the requestor. TheF field 1716 is used for status flags as needed.

The memory interface 1718 provides the interface and communication tothe system memory bus 322. All data read or written to the system memory(main or page storage) goes through this element.

The mapping table input register (MTIR) 1720 is a staging register forthe mapping table 1702. The mapping table input register 1702 can beloaded from either the control bus 320 or internally during theprocessing of records.

The mapping table output register (MTOR) 724 holds the mapping tableentry that is currently being processed. The records in each entryinclude:

a. the system memory address (MA) of the record to be processed;

b. the system memory increment (MI) to be used to find the next recordto be processed;

c. the record length (RL);

d. the record count (RC), i.e. the number of records to be processed bythis mapping table entry. The record count is decremented each time arecord is processed until it reaches zero, at which time no furtherrecords will be processed by this entry. A new entry must be reloaded tocontinue processing;

e. the Working Store address (WSA), i.e. the address of the record inthe Working Store 312 where data is to be read or written;

f. the Working Store increment (WSI) to be used to find the next recordto be read or written into the Working Store 312;

g. flags (F) (preferably 1 byte) which indicate processing options;

h. read/write flag (R/W) which specifies whether the operation is a readof the system memory (extraction) or a write to the system memory(assembly);

i. an extraction mask (EXM) which specifies the bytes that are to beprocessed through the crosspoint switch. The bits in the extraction maskindicate which switches are to be activated in the crosspoint, providingany byte to any byte connectively through the switch. The EXM fieldcontrols the connectivity state of each of the internal switches in thecrosspoint switch, via a decoder 1725;

j. a valid bit (V) which indicates that the mapping table entry isvalid.

The Working Store data register (WSD REG) 1726 is used to stage data toand from the Working Store. The storage buffer (SBUF) 1728 is used tostage data to and from the memory requestor. Finally, the Working Storeaddress register (WS ADR) 1730 holds the current Working Store address(modulo 8) being processed. This address is incremented by 1 for eachEXC iteration, using the adder 1732.

A counter 1731, under control of the control logic 1706, keeps track ofand selects (via the SBUF decoder 1729) the quadword in the storagebuffer 1728 being reordered through the crosspoint switch 1704. Theoutput of this counter 1731 is also used as a control input for thecross point switch decoder 1725 so that it selects the appropriateportion of the extraction mask for the selected quadword.

The control logic 1706 controls the operation of each of the otherelements in the extractor/memory interface unit. The control logic 1706can be a microprocessor running under microcode control, a conventionalmicrosequencer, or hardwired logic in the form of an applicationspecific integrated circuit (ASIC).

Adders 1734-1738 are provided to manipulate various fields in themapping table entries as they appear in the mapping table outputregister 1724. These manipulations include adding the memory increment(MI) to the memory address (MA), decrementing the record count (RC) andadding the Working Store increment (WSI) to the Working Store address(WSA).

The operation of the Extractor/Memory interface unit will now beexplained by reference to FIGS. 18A and 18B. FIGS. 18A and 18B are aflow chart of the operation of the memory interface/extractor unit. Thedescribed operations are performed under the control of the controllogic 1706. The flowcharted algorithm can be implemented as a microcodedprogram or as part of the control logic circuitry in an ASIC.

As previously explained, before a request is processed by theExtractor/Memory Interface Unit 308, the Control Processor 310 loads themapping table 1702 with the mapping table entry information required toprocess a given database command. The mapping table 1702 is loaded bythe Control Processor 310 by way of the control bus 320 and the mappingtable input register (MTIR) 1716. Each request for extraction operateson a group of records in the system memory. The records in a given groupare presumed to have a fixed record length (RL), and a fixed stride orincrement (MI) between them. Similarly, assembled groups of records arewritten back into the system memory with fixed record length and stride.

For each request for extraction or assembly, the control processor 310assigns an ID number which identifies a corresponding entry in themapping table 1702 and appropriately sets the read/write bit. Thecontrol processor 310 also builds and loads the extraction mask (EXM) soas cause the cross point switch 1704 to carry out a givenextraction/assembly request. The memory address (MA), the memoryincrement (MI), the record count (RC), and the record length (RL) areprovided to the control processor 310 as part of the database enginecommand block, received from the host processor.

For extraction, the Working Store address (WSA) and the Working Storeincrement (WSI) are determined by the control processor based on therecord lengths of the extracted records and conventional memory spaceallocation methods. For assembly, the Working Store address andincrement are determined from the actual location and stride of therecords as they appear in the Working Store 112.

In the idle state 1802, the Extractor/Memory Interface Unit 308 waitsfor the Control Processor 310 to place a request into its request queue1708. When the control logic 1706 determines that a request has beenentered into the queue 1708, it examines the ID 1710 and then reads thevalidity bit (V) of the entry corresponding to the ID, in the mappingtable (which is loaded with the entry by the control processor 310 alongwith the request) to determine if the request is valid (Step 1804).

If the validity (V) bit is not set (V=0) the control logic 1708 sends anerror message to the Control Processor 310 (Step 1806) and decrementsthe record count (RC) using the record count adder 1736 (Step 1808). Thecontrol logic 1706 then determines if the record count is 0 (Step 1810).If the record count is not 0, the control logic 1706 renters the idlestate (Step 1802) and waits for the next record. If the record count is0, the control logic resets the validity bit to 0 (Step 1812), sends aFINISHED message to the control processor 310 and reenters the idlestate (Step 1802) to wait for the next request. It should be understoodthat the validity bit is reset to 0 in step 1812 to handle the caseswhere this step is executed as a result of an entry into the algorithmat point A rather than due to an invalid ID entry.

If the validity bit is set (V=1), the control logic 1706 reads the R/Wbit of the entry (Step 1806) to determine whether the request is a READ(extraction) or a WRITE (assembly).

If the request is a write, the Extractor/Memory Interface Unit 308begins the assembly process. As a first step in the process, the controllogic 1706 loads the i-counter 1731 with an initial value of zero (step1818). The Working Store address (WSA) from the entry in the mappingtable output register 1724 (which is the entry corresponding to the IDof the request) is then loaded into the Working Store address register1730 (Step 1820). That being accomplished, the Working Store data fromthe Working Store address (held in WS ADR reg. 1730) is loaded into theWorking Store data register (WSD REG) 1726 (Step 1822). The controllogic 1706 then sets up the cross point switch 1704.

The cross point switch 1704 is set up by the extraction mask field (EXM)in the mapping table output register 1724 (Step 1824). One section ofthe extraction mask is provided for each quadword in the record. Eachsection is individually accessed by indexing the mask with the icounter. The mask section for a given quadword is decoded and thedecoded value sets up the crosspoint switch.

Once the crosspoint switch 1704 has been set up for the desiredconnectivity, the data from the Working Store data register 1726 isassembled into the store buffer (SBUF) 1728 (Step 1826). The i counter1731 is then incremented (Step 1828) and the i counter value (i.e. thequadword count) is compared to the record length (RL) in the mappingtable output register 1724 to determine if there are any more quadwordsin this record that need to be processed (Step 1830).

If there are more quadwords to be processed, the control logic 1706repeats the sequence of steps 1820-1830 for each quadword. If there areno additional quadwords to be processed, the control logic 1706initializes the memory requestor 1718 (step 1832) by providing it withthe record ID, the memory address (MA), the record length (RL) and theread/write control bit (R/W) from the mapping table output register1724. Once initialized, the memory interface 1718 requests a systemmemory write of RL quadwords to system memory starting at system memoryaddress MA (Step 1834). The memory address (MA) is then incremented bythe memory increment (MI) using the address adder 1734, and the entrywith the updated MA is written back into the mapping table 1702 via themapping table input register 1716. The updated entry is written into themapping table 1702 in preparation for the processing of the next recordto be processed under the request ID (Step 1836).

Once the entry in the mapping table has been set up for the next record,the control logic 1706 enters an idle loop (Step 1838) to wait for asignal from the host system, via the memory requestor 1718, that thememory request has been completed. When the control logic 1706 receivesthe request complete signal, it resets the memory requestor (Step 1840)and reenters the algorithm at point A.

A read request (extraction) is handled in a reverse manner to a writerequest (assembly). Upon determining that the request is a READ (step1816), the control processor initializes the memory interface the therecord ID, memory address (MA), record length (RL) and read/write bit(R/W) (Step 1842). The memory interface then requests a read from systemmemory of RL quadwords starting at system memory address MA. The memoryincrement is then added to the memory address to prepare for theprocessing of the next record and the updated entry is rewritten intothe mapping table (Step 1846). The the control logic 1706 then enters anidle loop to wait for the memory request to be complete (Step 2348).

Once informed that the memory request is complete, the control logic1706 loads the store buffer 1728 with the data received from the memoryinterface 1718 and resets the i-counter 1731 to zero (Step 1850). Thecontrol logic 1706 then sets up the crosspoint switch with theextraction mask (EXM) (Step 1852) in a similar manners to that describedfor step 1824. The quadword from the store buffer 1728 is the extractedvia the crosspoint switch 1704 to the Working Store data register 1726(Step 1854).

Once the record data has been extracted into the Working Store dataregister 1726, it is written to the Working Store 312 (FIG. 3). This isaccomplished by writing the Working Store address (WSA) from the mappingtable output register 1724 into the Working Store address register(1730) (Step 1856) and then writing the Working Store data from the WSDregister 1726 into the Working Store 312 at the Working Store address inthe Working Store address register 1730 (Step 1858).

Once the first quadword has been written to the Working Store 312, thecontrol logic 1706 sets up the Extractor/Memory interface Unit toaccommodate the next quadword in the record. Using the WS address adder1732, the Working Store address is then incremented by the Working Storeincrement (typically one quadword) and the updated entry is written backinto the mapping table 1702 (Step 1860). Further, the i counter value isincremented by one (Step 1862). If the i counter value is not yet equalto the record length (RL) in the mapping table output register 1724 (asdetermined by step 1864), steps 1852-1864 are repeated for the remainingquadwords. If all of the quadwords in the record have been processed,the control logic resets the memory requestor 1718 (Step 1866) andreenters the algorithm at point A to prepare for processing the nextrecord.

j. Enhancements and Improvements

The sorting performance of the Database Engine could be further improvedthrough several modifications to the Database Engine hardware.

First, the Working Store 312 could be partitioned into four separateblocks of storage that allow simultaneous access for fetch operations. Asort engine with four comparators and four sets of pointer arrays couldbe used to simultaneously sort four blocks of keys. If the comparatorsare four-way comparators, i.e. four keys are compared and one key isdetermined to be the winner, then this engine can compare sixteen keysand produce 4 winners in one Database Engine clock cycle. Eachcomparator and its associated pointer arrays performs a four-way mergesort of the keys in its Working Store partition. A final pass throughone of the engines (4-way merge of the 4 sorted blocks) would produces asingle sorted list of keys. FIG. 22 is a block diagram of a four-pipe,four-way comparator sort engine.

As illustrated in FIG. 19, the sort engine of the Sort/Merge Unit canalso be modified to perform a front-back merge, effectively doubling thebinary merge performance of the Sort/Merge Unit engine. This requiresthe replication of the pointer arrays 1902-1908 and the key comparator1912. One comparator and pointer array set is initialized to start atthe beginning of the lists and merge in ascending order. The other setis initialized to start at the end of the list and merge in descendingorder. This hardware can perform a parallel binary merge sort of theWorking Store 312 in one half the time of conventional sort engines.

As described herein, the merge pass of the sort process is improved byperforming an N-way merge of the keys. Since the Working Store 312 willalways be limited in size by technology constraints, the sort enginemust sort Working Store size blocks of keys and store them back to thesystem memory. When all of the blocks have been sorted, a final mergepass is used to create one sorted list of keys. A 16-way merge can beimplemented with a two-way comparator and a tree of pointers and offsets(codewords). Since it is a two way comparator, the tree is 4 levels deepand the merge produces a result in, at most, every 4 cycles. A moreefficient method is to use the 4-way comparators as illustrated in FIG.20 and create a 16 way merge tree out of five 4-way comparators2002-2010. The performance of such a tree is one result every twocycles. Thus, 16 lists of N keys can be merged in 2*16*N=32N cycles(minimum) compared to the 4*16*N=64N cycles for the 2-way comparator anda 16-way merge.

FIG. 21 shows a 4-way comparator 2102 which does not produce a winningkey, but produces an ordered list of pointers to the four input keys.The output is four two-bit pointers which order the input words ineither ascending or descending order. With the addition of pointerarrays and control logic as used in the sort/merge unit (DBSM) 302, theoutputs can be used to control the update of the pointer arrays,reordering 4 pointers per cycle. Thus, four keys can be sorted in onecycle as compared with one key per cycle in the embodiment of FIGS. 7and 11. This technique could be used to enhance the performance of thebinary merge sort by partially pre-sorting the data. Thus, the binarymerge sort can start with a list length (p in FIG. 10A) of 4,eliminating two passes through the data.

The foregoing description of the preferred embodiments of the inventionhave been provided for the purposes of example and description. Thoseskilled in the art will understand that many variations andmodifications to the described embodiments that fall within the spiritand scope of the invention. It is intended that the scope of theinvention be limited only by the claims.

Having thus described our invention, what we claim as new and desire tosecure by Letters Patent is:
 1. An attached coprocessor for processingdatabase records stored in a system memory of a host system, responsiveto database processing commands stored in the system memory andgenerated by a database processing program, said coprocessorcomprising:first bus means for carrying control information; second busmeans for carrying data; extractor means for extracting fields from therecords and for reordering said fields based on said commands, theextractor means being in communication with the system memory, the firstbus means and the second bus means; controls means communicating withsaid host system, for providing control information on the first busmeans responsive to the commands, the control means being incommunication with the first bus means and the second bus means; searchmeans for processing search queries responsive to the control means, thesearch means being in communication with the first bus means and thesecond bus means; sort means for performing sort and merge operations onthe database records responsive to the control means, the sort meansbeing in communication with the first bus means and the second busmeans; hash generator means for generating a hash code from keysprovided in the database processing commands the hash generator meansbeing responsive to the control means and in communication with thefirst bus means and the second bus means; and memory means fortemporarily storing internal data, the memory means being incommunication with the second bus means whereby said search means, saidsort means, and said hash generator means utilize said memory means incommon.
 2. The attached coprocessor of claim 1 wherein the sort meanscomprises codeword tree means for performing tournament tree codewordsorting of the database records.
 3. The attached coprocessor of claim 1wherein the system memory comprises a paging memory coupled to the hostsystem and wherein the extractor means comprises means for directlyaccessing the paging memory.
 4. The attached coprocessor of claim 3wherein the paging memory is multiported and wherein the extractor meanscomprises a data and address bus connected to a port of the pagingmemory.
 5. The attached coprocessor of claim 1 wherein the sort meanscomprises means for performing a front-back merge of the databaserecords.
 6. An attached coprocessor for performing a plurality ofdatabase functions on database records stored in a system memory of ahost computer, said coprocessor comprising:control bus means; data busmeans; control processor means communicating with said host computer,for parsing a database command received from said system memory, saidparsed database command including a selected set of said plurality ofdatabase functions, said control processor means controlling saidcontrol bus means in accordance with said selected set of said pluralityof database functions, said control processor means being incommunication with said control bus means and said data bus means;processing means for selecting database fields from the database recordsand for manipulating said database fields in accordance with saidselected set of said plurality of database functions, said control busmeans and said data bus means connecting said processing means with saidsystem memory; said processing means including a plurality of processingelements for performing said plurality of database functions, saidprocessing elements being invoked in accordance with said selected setof said plurality of database functions, said plurality of processingelements including, search means for selecting desired ones of saiddatabase fields, said search means being responsive to said controlprocessor means and said search means being in communication with saidcontrol bus means and said data bus means; sort means for performingsort and merge operations on said database records, said sort meansbeing responsive to said control processor means and said sort meansbeing in communication with said control bus means and said data busmeans; hash code generator means for generating a hash code based on akey field in said database record, said hash code being used by saidplurality of processing elements, said hash code generator means beingresponsive to said control processor means and said hash code generatormeans being in communication with said control bus means and said databus means; and memory means for temporarily storing internal data, thememory means being in communication with said data bus means wherebyeach of said plurality of processing elements utilize said memory meansin common.
 7. An attached coprocessor, as recited in claim 6, whereinsaid sort means comprises codeword tree means for performing tournamenttree codeword sorting of said database records.
 8. An attachedcoprocessor, as recited in claim 6, wherein said system memory comprisesa paging memory coupled to said host computer and wherein said controlprocessor means comprises means for directly accessing said pagingmemory.
 9. An attached coprocessor, as recited in claim 8, wherein saidpaging memory is multiport and wherein said control processor meanscomprises a data and address bus connected to a port of said pagingmemory.
 10. An attached coprocessor, as recited in claim 6, wherein saidsort means comprises means for performing a front-back merge of saiddatabase records.